Alvaro Morata put Spain ahead inside 10 minutes on what appeared to be another routine day at the office, before goals from Nikola Kalinic and Ivan Perisic handed Croatia a famous win.
This was expected to be Spain's sternest test of the tournament but it was business as usual from the off, as Morata gave his side the lead after just seven minutes.
David Silva's exquisite reverse ball bypassed four Croatia players to find Cesc Fabregas, whose chip over the onrushing Danijel Subasic's was met by Morata and prodded over the line.
Spain was going through the gears and Nolito went close a minute later, his side-foot volleyed effort from Jordi Alba's cross eventually floating harmlessly wide.
Whether it was complacency or nerves creeping into the Spanish team, the defense gifted Croatia's front line two guilt-edged chances in two minutes.
First, captain Sergio Ramos' sloppy pass was intercepted by Nikola Kalinic but his 20-yard shot was comfortably palmed behind for a corner by David De Gea.
Moments later, De Gea's errant pass found the feet of Ivan Rakitic but his chipped effort hit the crossbar, post, and Gerard Pique on the line and incredulously stayed out.
A minute before half time, Morata should have scored Spain's second. The Juventus striker, who had his buy-back clause activated by Real Madrid Tuesday, was found by Fabregas but his first touch was loose and the ball rolled harmlessly into Subasic's grateful arms.
And his profligacy would soon be punished.
With Spain still ruing the missed chance, Croatia countered with the ball eventually making its way to Ivan Perisic on the left wing. The Inter Milan forward's stepovers and Cruyff turn baffled Juanfran and his cross into the box was met by Kalinic's deft flick, diverting the ball past De Gea.
It was the first goal Spain had conceded at a European Championship since Italy forward Antonio Di Natale beat Iker Casillas in June 2012 -- 734 minutes of football.
Croatia began the second half much as it ended the first and Perisic almost gave his side the lead with an acrobatic overhead kick after yet another De Gea error.
But, with 20 minutes left to play, Spain was handed the chance to retake the lead from the penalty spot.
Andres Iniesta, unusually quiet by his high standards, picked out Silva's run and the Manchester City man went down under pressure from Sime Vrsaljko, prompting Dutch referee Bjoern Kuipers to point to the spot.
Despite a plethora of technical talent in the team, defender Ramos opted to take the penalty and hammered it down the middle, Subasic guessing correctly and palming the ball away to safety.
With Spain pressing for a winner, Croatia appeared content to hold on for a draw. However, with three minutes remaining, Iniesta's blocked shot initiated a blistering Croatian counter-attack which ended with Perisic's shot deflecting off Pique's studs and beating De Gea at his near post.
While the hoards of Croatian fans celebrated deliriously in the stands, the job on the pitch was far from finished as Vrsaljko completed his transition from villain to hero by blocking Silva's goal-bound shot on the line with the last kick of the game.
It handed Spain a first defeat at a European Championship since 2004, when Portugal knocked it out, to set up a rematch of the 2012 final against Italy in the last 16.
Meanwhile, Turkey's 2-0 defeat of the Czech Republic wasn't enough to sent it through to the knockout stage.
Despite goals from Burak Yilmaz and Ozan Tufan, Turkey's negative goal difference ensured Northern Ireland progressed to the last 16 as one of the best third place teams.