Ivan Perisic struck a sensational winner three minutes from time as Croatia ended Spain's 14-game unbeaten run at the European Championship finals to top Group D after a 2-1 victory on Tuesday.
Spain will now face Italy in the last 16 in Paris on Monday in a repeat of the 2012 final.
Alvaro Morata's early strike got Spain off to a flying start. But despite the absence of Luka Modric through injury, Croatia battled back to equalise before half-time through Nikola Kalinic.
Spain captain Sergio Ramos saw a penalty saved by Danijel Subasic 18 minutes from time.
And that miss proved vital when Perisic snuck the ball home at David de Gea's near post.
Croatia meet one of the best third-placed sides in Lens on Saturday.
Spain could also have to face world champions Germany in the quarter-finals and hosts France in the semi-finals if they are to reach the final in Paris on July 10.
"Now we have to dance with the favourites, but to be champions you have to beat everyone," said Ramos, who vowed Spain will learn from their mistakes.
Coach Vicente del Bosque would rather have avoided an early meeting with the on-form Italians.
- Italy clash -
"It is not ideal, that would have been to finish first (in the group)," said Del Bosque.
"We have to recover well. We are prepared to turn this situation around."
Morata's return to European champions Real Madrid from Juventus had been confirmed earlier on Tuesday.
And he moved level with club teammate Gareth Bale on three goals in the fight for the golden boot by finishing off a slick Spanish move after seven minutes.
David Silva's cute reverse pass picked out Cesc Fabregas's run and the Chelsea midfielder's cross was tapped into an empty net by Morata.
Spain looked rarely troubled at the back in their opening two games, but were given plenty of problems by Croatia even without star midfielder Modric.
Kalinic stung the palms of David de Gea before forcing an error from the Manchester United 'keeper as he dallied.
The loose ball fell to Ivan Rakitic and his brilliant chipped effort floated over Barcelona teammate Gerard Pique on the line before coming back off both the crossbar and post.
Morata had a great chance to double Spain's lead when he failed to control Fabregas's fine through ball with just Subasic to beat.
However, Del Bosque's men were pegged back right on half-time when Perisic's cross from the left was flicked home by Kalinic.
It was the first time Spain had conceded in 11 competitive games stretching back to October 2014 and first time they had conceded in the Euros for a record 733 minutes.
The goal knocked Spain out of their stride as Croatia pushed them onto the back foot at the start of the second period.
De Gea saved from Tin Jedvaj to atone for his own error in flapping at a cross before Marko Pjaca sent an acrobatic effort just wide from the rebound.
Pjaca also had claims for a penalty waved away as Croatia threatened the goal that would have taken them top of the group.
Del Bosque withdrew front two Nolito and Morata for the more physical presence of Bruno Soriano and Aritz Aduriz.
Spain were then handed a great chance to retake the lead when referee Bjorn Kuipers adjudged Silva had been pushed by Sime Vrsaljko inside the area.
Modric appeared to send on a message to Subasic when he saw his Real Madrid teammate Ramos step up to take the spot-kick.
And Subasic got lucky as his save was allowed to stand despite the fact he had encroached well before Ramos took aim.
Croatia took full advantage to blow the tournament wide open as Perisic lashed home to round off a clinical counter-attack.
AFP
Wed Jun 22 2016
![Euro 2016: Perisic winner stuns champions Spain Euro 2016: Perisic winner stuns champions Spain](https://resizer-awani.eco.astro.com.my/tr:w-177,h-100,q-100,f-auto/http://img.astroawani.com/2016-06/41466557305_CroatiaVsSpain.jpg)
Croatia's midfielder Ivan Perisic (R) celebrates his goal during the Euro 2016 group D football match between Croatia and Spain at the Matmut Atlantique stadium in Bordeaux on June 21, 2016. - AFP PHOTO / GEORGES GOBET
![Proses libat urus Belanjawan 2025 berjalan lancar - Fahmi Proses libat urus Belanjawan 2025 berjalan lancar - Fahmi](https://resizer-awani.eco.astro.com.my/tr:w-177,h-100,q-100,f-auto/https://img.astroawani.com/2024-08/41723708198_TBFAhmi.jpg)
Proses libat urus Belanjawan 2025 berjalan lancar - Fahmi
Proses libat urus Kementerian Kewangan dengan pihak pemegang taruh bagi tujuan penyiapan dokumen Belanjawan 2025 berjalan lancar.
![Projek LCS: Mahkamah arah bekas Pengarah Urusan BNS dirujuk pakar psikiatri Projek LCS: Mahkamah arah bekas Pengarah Urusan BNS dirujuk pakar psikiatri](https://resizer-awani.eco.astro.com.my/tr:w-177,h-100,q-100,f-auto/https://img.astroawani.com/2024-08/51723717543_tbAhmadRamli.jpg)
Projek LCS: Mahkamah arah bekas Pengarah Urusan BNS dirujuk pakar psikiatri
Mahkamah Sesyen mengarahkan bekas Pengarah Urusan BNS Tan Sri Ahmad Ramli Mohd Nor, dirujuk ke bahagian psikiatri di Hospital Kuala Lumpur.
![Amaran gempa bumi di Jepun selama seminggu berakhir selepas tiada perkembangan baharu Amaran gempa bumi di Jepun selama seminggu berakhir selepas tiada perkembangan baharu](https://resizer-awani.eco.astro.com.my/tr:w-177,h-100,q-100,f-auto/https://img.astroawani.com/2024-08/71723718198_tokyo.jpg)
Amaran gempa bumi di Jepun selama seminggu berakhir selepas tiada perkembangan baharu
Nasihat gempa bumi Palung Nankai mendorong kerajaan pusat dan komuniti tempatan untuk memperhebatkan persiapan bencana sejak minggu lepas.
![Jenazah ibu Menteri Besar Kedah selamat dikebumikan Jenazah ibu Menteri Besar Kedah selamat dikebumikan](https://resizer-awani.eco.astro.com.my/tr:w-177,h-100,q-100,f-auto/https://img.astroawani.com/2024-08/51723717957_IbuMBKedahmenigg.jpg)
Jenazah ibu Menteri Besar Kedah selamat dikebumikan
Jenazah Allahyarham Meriam Ahmad, 74, ibu Menteri Besar Kedah, selamat dikebumikan di Tanah Perkuburan Islam Sungai Pau jam 5.45 petang Khamis.
![Pengarah SRC adalah profesional, bukan boneka yang diupah oleh Najib - Ismee Pengarah SRC adalah profesional, bukan boneka yang diupah oleh Najib - Ismee](https://resizer-awani.eco.astro.com.my/tr:w-177,h-100,q-100,f-auto/https://img.astroawani.com/2024-08/81723717419_tbIsmeeIsmail.jpg)
Pengarah SRC adalah profesional, bukan boneka yang diupah oleh Najib - Ismee
Mahkamah Tinggi diberitahu bahawa Ahli Lembaga Pengarah SRC International adalah sekumpulan profesional dan bukannya 'boneka' Najib.
![Mesir tekankan keperluan gencatan senjata segera di Gaza Mesir tekankan keperluan gencatan senjata segera di Gaza](https://resizer-awani.eco.astro.com.my/tr:w-177,h-100,q-100,f-auto/https://img.astroawani.com/2024-08/71723717873_BadrAbdelatty.jpg)
Mesir tekankan keperluan gencatan senjata segera di Gaza
Pendekatan itu adalah satu-satunya cara menghentikan peningkatan ketegangan serantau dan membendung percubaan untuk meluaskan konflik.
Berita Terkini Kita: Hero Kita: Kisah wira negara yang tidak didendang
Irfan Faruqi menjelajah Johor membawakan kisah-kisah wira tidak didendang yang memainkan peranan penting dalam pembangunan negara bersempena bukan kemerdekaan.
Niaga AWANI: Potongan 50 peratus bagi pendaftaran domain .my dan .com.my
MYNIC Berhad, agensi di bawah Kementerian Digital menyemarakkan sambutan Bulan Kebangsaan dengan memberi potongan harga hingga 50 peratus bagi pendaftaran domain .MY dan .COM.MY yang baharu.
Niaga AWANI: K'jaan Persekutuan, Negeri perlu tingkat kepantasan beri kelulusan untuk tarik pelabur – PM
Kerajaan Persekutuan, negeri dan pihak berkuasa tempatan perlu meningkatkan kepantasan dalam memberi kelulusan tanpa berkompromi dengan peraturan yang dikuat kuasa bagi menjadikan Malaysia tumpuan pelabur di rantau ini, kata Perdana Menteri Datuk Seri Anwar Ibrahim.
Niaga AWANI: KDNK Jepun meningkat 3.1 peratus tahun ke tahun pada suku kedua
Keluaran Dalam Negara Kasar (KDNK) Jepun mencatatkan pertumbuhan 3.1 peratus tahun ke tahun pada suku tahun kedua tahun ini, menurut data awal yang dikeluarkan kerajaan Jepun, lapor Sputnik.