Mallorcan Marco Asensio struck in an extra-time winner as Spain ended Japan's hopes of Olympic gold in men's football with a 1-0 (aet) victory, setting up a clash with Brazil in Saturday's final.
Defending champions Brazil also had to struggle to make the final, beating Mexico 4-1 on penalties after the game ended goalless after extra-time. Japan had matched Spain throughout the game, playing with creativity and invention going forward and tenacity without the ball and they were five minutes away from taking the match to a penalty shootout.
After a cagey first half, Spain thought they had a great chance to go in front when referee Kevin Ortega of Peru pointed to the penalty spot after Mikel Merino went down under challenge from Maya Yoshida.
But the video assistant referee ordered Ortega to go to the pitchside monitor and he saw the clear images that Yoshida had made a perfectly fair and well-timed challenge.
That overturned penalty sparked both sides into life and it was a lively second half with openings at both ends.
Japan keeper Kosei Tani did well to race out quickly and smother Rafa Mir as the ball broke to him close to goal while at the other end Takefusa Kubo's blast at the near post was parried by Unai Simon.
Both teams were unable to make the most of half-chances, however, and the game followed a similar pattern into extra-time before former Real Mallorca forward Asensio picked the ball up in the inside right channel, glanced up and curled the ball into the far corner. Spain are looking to repeat their gold medal success from the Barcelona Games in 1992 but will have to beat the Rio winners from five years ago.