La Roja achieved a showdown against the 2016 gold medal winners by defeating the tournament host for Japan after extra time
Spain will face Brazil in the semi-finals of the Men’s Olympics, after penalties and extra time.
La Roja booked its place in the top match by beating the tournament hosts 1-0 on Tuesday.
Marco Asensio scored the only goal of the match in extra time to set up a final encounter with Brazil at Yokohama International Stadium, and the Selecao defeated Mexico with penalties.
Spain is past hosts
Japan have taken Spain to extra time in the last four games, but have stuck to a disciplined form of defense while looking for opportunities to beat their opponents at half-time.
La Roja were denied a penalty kick after a VAR review, but neither side really seemed to break the deadlock in the first 90 minutes, and extra time was needed to find a winner.
Asensio finally became the winner of the match in the 116th minute and received the ball just inside the box before curling a beautiful shot into the corner of the net.
How did Brazil reach the final?
Brazil’s path to the final was even more difficult as they were penalized by Mexico after a 0-0 draw after 120 minutes.
The Selecao won the match 4-1 thanks to successful kicks from Dani Alves , Gabriel Martinelli , Bruno Guimares and Reinier , which advanced to their second consecutive Olympics in the process.
When is the final played?
The final takes place at Saturday 7 August at 11:30 (BST) at the International Stadium in Yokohama.
Both Brazil and Spain will win gold medals for the second time in their respective history, while La Roja won the tournament in 1992, while the Selecao won in 2016.
When does the Bronze Medal Match take place?
Japan and Mexico meanwhile still have the chance to win the consolation prize of a bronze medal.
The two teams will meet at Saitama Stadium 11 a.m. (BST) on August 6 in a repeat of their group stage meeting earlier in the tournament, which ended 2-1 for Japan.