Substitute Juanlu Sanchez struck a late winner as Spain came from behind to beat Morocco 2-1 on Monday and reach the final of the Olympic men’s football.
Morocco had led in the semi-final through a Soufiane Rahimi penalty towards the end of the first half at the Stade Velodrome in Marseille.
However, Barcelona’s Fermin Lopez equalised midway through the second period and then set up Sevilla right-back Sanchez to fire in the winner.
It is Spain’s second consecutive appearance in the final of the Olympic men’s football. They had to settle for silver three years ago in Tokyo after losing in extra time to Brazil.
Spain, who are chasing a second gold after triumphing in Barcelona in 1992, go to Paris for the final on Friday against either hosts France or Egypt, who play their last-four tie later.
Morocco can still claim a first medal by winning the bronze medal match, which will take place on Thursday in Nantes.
Last year’s Under-23 Africa Cup of Nations winners had impressed on their run to the semi-finals and looked on course to shock Spain when they went ahead in the 37th minute thanks to the prolific Rahimi.
Morocco were awarded a penalty following a VAR check for a foul by Pablo Barrios on Amir Richardson in the box, and Rahimi stepped up to send the goalkeeper the wrong way from the spot.
It was a sixth goal of the Olympics for the tournament’s leading scorer, with four of his strikes coming from the penalty spot.
That sent the large Moroccan support wild but Spain kept their cool to equalise through their own star man in the 66th minute.
Lopez, a member of Spain’s triumphant Euro 2024 squad who scored twice in the Olympic quarter-final against Japan, pounced to snatch possession when the ball broke loose in the box and fired low into the net to make it 1-1.
With the prospect of extra time looming, Spain won it in the 85th minute as Lopez found Sanchez bounding into the area, and he sent a shot low into the far corner.