Defending champion Brazil will face Spain for the Olympic gold medal in men's soccer on Saturday.
Spain beat host Japan 1-0 Tuesday with Marco Asensio scoring a curling shot in the 115th minute in Saitama. Brazil was taken to penalties by Mexico, winning the shootout 4-1 after a scoreless draw in Kashima.
Brazil goalkeeper Santos stopped Mexico's first penalty from Eduardo Aguirre, and Johan Vasquez's attempt then hit the post. Reinier converted the winning kick for Brazil.
Mexico will play Japan for the bronze medal in Saitama on Friday. The gold-medal match is set for Saturday in Yokohama.
Brazil won its first Olympic title at the 2016 Rio de Janeiro Games in a penalty shootout with Germany. Neymar converted the clinching penalty at the iconic Maracana Stadium.
Spain's only Olympic title also came at home — at the 1992 Barcelona Games. The country's last final was at the 2000 Sydney Games, losing to Cameroon.