Spain saw off host Japan 1-0 on Tuesday to set up an Olympics final date with reigning champion Brazil, who earlier edged out Mexico in a penalty shootout.
Marco Asensio's superb extra-time winner secured the in Saitama.
The Real Madrid winger came off the bench as a substitute and curled in a terrific strike in the 115th minute, sending Spain through to a first Olympic final since it finished runner-up at the 2000 Games in Sydney.
Japan will take on Mexico in Friday's bronze medal match. Mexico lost 4-1 on penalties to Brazil in Kashima following 120 goalless minutes.
Having needed a last-gasp equalizer against Ivory Coast in the previous round before prevailing 5-2 after extra time, Spain created the better chances over the 90 minutes against Japan without making a breakthrough.
Japan goalkeeper Kosei Tani produced a key save to deny Rafa Mir in the first half, while VAR (Video Assistant Referee) intervened to overturn a penalty awarded to Spain after a tackle by Maya Yoshida on Mikel Merino.
Takefusa Kubo had a shot batted away by Unai Simon before Japan withstood a late siege, as Kou Itakura threw himself in the way of Martin Zubimendi's strike before Mir fired against the legs of Tani.
As a shootout beckoned Asensio conjured up a touch of magic, spinning free inside the area and bending his effort beyond Tani's despairing dive.
Earlier, Brazil goalkeeper Santos saved Eduardo Aguirre's penalty in a shootout before Johan Vasquez smacked the post with Mexico's second attempt.
Dani Alves, Gabriel Martinelli, Bruno Guimaraes and Reinier all scored for Brazil, who will be appearing in a fifth Olympic final in Yokohama.
"It's very special to be able to take part in an Olympic Games and to get to the final. It's a really happy moment for me," said veteran Brazil captain Alves, who at 38 is one of three over-age players in the squad.
"Since the very start we set ourselves the aim of seeking going, and I think we are deservedly in the final."
Mexico, who beat Brazil to win gold at London 2012, had scored 14 goals in four matches in this year's tournament – including six in its quarterfinal victory over South Korea.
Its best period against a disciplined Brazil came at the end of the first half as Luis Romo forced an excellent save from Santos, with Uriel Antuna's goalbound effort then blocked by Diego Carlos.
Brazil saw a penalty decision overturned by VAR after Jose Esquivel appeared to foul Douglas Luiz in the box.
Everton forward Richarlison, the competition's top scorer with five goals, nearly won the game for Brazil just before the end of normal time but his glancing header bounced back off the post.
Brazil won the 2016 final against Germany on penalties and is attempting to join Britain, Uruguay, Hungary and Argentina by defending its Olympic crown. Spain won the 1992 Games on home soil in Barcelona.
Please click to read our informative text prepared pursuant to the Law on the Protection of Personal Data No. 6698 and to get information about the cookies used on our website in accordance with the relevant legislation.
6698 sayılı Kişisel Verilerin Korunması Kanunu uyarınca hazırlanmış aydınlatma metnimizi okumak ve sitemizde ilgili mevzuata uygun olarak kullanılan çerezlerle ilgili bilgi almak için lütfen tıklayınız.