Iago Aspas scored a stoppage-time equaliser - with the aid of VAR - as Spain scraped an unconvincing draw with Morocco to top Group B and secure a last-16 tie against World Cup hosts Russia.
Youssef En-Nesyri - who plays in Spain for Malaga - looked to have won it for Herve Renard's side when he powered in a superb header from fellow substitute Faycal Fajr's corner.
But Aspas flicked in Dani Carvajal's low cross to make it 2-2, with referee Ravshan Irmatov initially disallowing the goal before overturning the decision.
Spain won the group on goals scored as Portugal were held to a 1-1 draw by Iran - but had a tough night.
A dreadful mix-up between Andres Iniesta and Sergio Ramos had allowed Khalid Boutaib to stride through and give Morocco a surprise 14th-minute lead.
Iniesta made amends five minutes later by helping create a sublime equaliser, exchanging passes with Diego Costa and getting to the byeline before cutting back for Isco to steer high into the net.
But Spain looked wobbly in defence when pressed by a committed, aggressive Morocco side, with Boutaib denied by the legs of David de Gea after Hakim Ziyech's quick throw sent him clear.
Nordin Amrabat was desperately unlucky not to score in the second half as his searing shot came back off the angle of post and bar with De Gea motionless.
Isco was denied a second goal when his header was diverted wide by Romain Saiss - playing instead of dropped captain Medhi Benatia - before the late drama.
Latest Stories
-
Center for Learning and Childhood Development Director Dr Kwame Sakyi honoured at Ghana Philanthropy Awards
7 hours -
Asantehene receives 28 looted artefacts
8 hours -
CAF WCL 2024: Ghana’s Thelma Baffour wins title with TP Mazembe
9 hours -
Benjamin Boakye slams politicisation of energy sector issues and ECG’s inefficiencies
9 hours -
Erastus Asare Donkor and Dr Neta Parsram win big at 10th Mining Industry Awards
10 hours -
Government is “suppressing information” about power sector challenges – IES Director
10 hours -
Majority of our debts caused by forex shortfall – ECG Boss
10 hours -
Pan-African Savings and Loans supports Ghana Blind Union with boreholes
11 hours -
Bole-Bamboi MP Yussif Sulemana donates to artisans and Bole SHS
11 hours -
Top up your credit to avoid potential disruption – ECG to Nuri meter customers
11 hours -
Dutch & Co wins 2024 Entrepreneur of the Year Award
11 hours -
We’ll cut down imports and boost consumption of local rice and other products – Mahama
13 hours -
Prof Opoku-Agyemang donates to Tamale orphanage to mark her birthday
15 hours -
Don’t call re-painted old schools brand new infrastructure – Prof Opoku-Agyemang tells gov’t
15 hours -
Sunon Asogli plant will be back on stream in a few weeks – ECG
15 hours