Ivan Perisic’s late goal saw Croatia come from behind to beat defending champions Spain and advance to the knockout stages of Euro 2016 as Group D winners.
Alvaro Morata’s early strike had given Spain the lead but Nikola Kalinic equalised just before half-time before La Roja defender Sergio Ramos’s penalty was saved midway through the second half.
Croatia then snatched the points three minutes from time when Perisic finished past David de Gea at his near post.
The 2-1 defeat means Spain finish second to Croatia and will meet Italy in the round of 16 on Monday in a repeat of the 2012 final.
Morata opened the scoring in just the seventh minute as the forward stole in to poke home Cesc Fabregas’ effort from virtually on the goal-line.
An error by De Gea almost allowed Ivan Rakitic to equalise but the Barcelona midfielder’s lofted attempt came back off the crossbar after possession had been gifted to Croatia.
David Silva hit a shot straight at Danijel Subasic before Nolito had an effort deflected wide as Spain looked to add to their lead.
Morata had the best chance to do just that but he wasted a chance with a poor touch having been slipped in by Fabregas just before the break.
Croatia made them pay as they levelled on the stroke of half-time when Perisic crossed for Kalinic to flick home past De Gea.
The Manchester United goalkeeper was almost caught out once again in the second half, Marko Pjaca’s overhead kick flashing just wide with De Gea stranded having failed to claim a cross.
Pjaca then had a penalty shout turned down after hitting the ground following a challenge by Ramos, who then headed a corner wide when free inside the Croatia box.
While referee Bjorn Kuipers had made the correct decision at one end, the Dutch official subsequently awarded a soft spot-kick to Spain after Andres Iniesta’s lofted pass into Silva led to the Manchester City midfielder going down under pressure from Sime Vrsaljko.
Justice was done as Subasic saved Ramos’s penalty, although it led to more controversy as the goalkeeper was almost six yards off his line by the time the Real Madrid man struck his effort.
It was Croatia who ended the night as group winners after Kalinic found Perisic, whose low drive beat De Gea – with the 25-year-old again not at his best.
CROATIA: Subasic, Srna, Corluka, Jedvaj, Vrsaljko, Rog (Kovacic 82), Badelj, Perisic (Kramaric 90), Rakitic, Pjaca (Cop 90), N Kalinic. Subs not used: Vargic, Strinic, Modric, Schildenfeld, Brozovic, Mandzukic, Coric, Vida, L Kalinic.
SPAIN: De Gea, Juanfran, Pique, Sergio Ramos, Jordi Alba, Fabregas (Thiago 84), Busquets, Iniesta, Silva, Morata (Aduriz 67), Nolito (Bruno 60). Subs not used: Casillas, Azpilicueta, Bartra, Koke, Lucas, Pedro, Bellerin, San Jose, Sergio Rico.