The new tournament favourites were handed a reality check by the new Euro 2016 contenders.
When the teamsheets came out, Spain would have been forgiven for sensing that Croatia were there for the taking. And when they carved the Croatia defence apart after just seven minutes, the holders looked like they were on their way to a third straight victory at Euro 2016.
But Croatia, with five changes to their starting XI, had other ideas at the Stade de Bordeaux.
Striker Nikola Kalinic, in for Mario Mandzukic, cancelled out Alvaro Morata's opener on the stroke of half-time with a volley.
Ante Cacic's other changes - Sime Vrsaljko, Tin Jedvaj, Marko Rog, and Marko Pjaca - all shone at the Stade de Bordeaux.
They might have been without injured midfielder Luka Modric, the heartbeat of the Croatia team, but they did not miss him on Tuesday.
Buoyed by Danijel Subasic's 70th-minute penalty save from Sergio Ramos, Croatia pressed on for a winner.
It came 17 minutes later. Kalinic turned provider, with Ivan Perisic finishing from a tight angle to ensure that Croatia reached the last 16 as Group D winners while Spain would be runners-up.
Not many managers have rotated their squads to good effect. Didier Deschamp's decision to drop Paul Pogba and Antoine Griezmann for France's game against Albania did not bear fruit. Roy Hodgson's gamble of making six changes to his England side against Slovakia saw them drop from Group B leaders to runners-up.
But Cacic showed that he knows how to utilise his talented, deep squad. Jedvaj, 20, Rog, 20, and Pjaca, 21 provided the team with pace and energy. Croatia had to chase the ball against the masters of possession. Yet they had more shots on target (4-3) with 40 per cent of the ball.
Tipped as dark horses before the start of competition, Croatia have proven that they cannot be underestimated.
- Spain took the lead after seven minutes. David Silva attracted the attention of three defenders but managed to slip a pass into the penalty box for Cesc Fabregas to chase. The midfielder fired across the face of the goal and Morata tapped home.
- Five minutes later, Ramos gifteed the ball to Kalinic. The striker's shot from outside the box is turned away by David de Gea for a corner. The set-piece did not cause further trouble.
- In the 14th minute, de Gea attempted to play the ball out from the back. He was caught in possession by Kalinic, who passed to Ivan Rakitic. With de Gea off his line, the midfielder went for a chip. It hit the underside of the crossbar, then the post, before de Gea rushed back to claim the ball.
- On the stroke of half-time, Kalinic gave Croatia a deserved equaliser following good work by Perisic on the left flank. Perisic worked some space with a stepover and a drag back before delivering a cross into the six-yard box. Kalinic got across Ramos and volleyed the ball into the net.
- In the 57th minute, Darijo Srna's cross into the box was punched away by de Gea. The ball fell to Rakitic, whose shot was blocked. Pjaca attempted an overhead kick but that effort was wide.
- In the 70th minute, Spain were awarded a penalty after Srna was adjudged to have brought Silva down in the box. Ramos stepped up and shot straight at Subasic.
- In the 87th minute, Croatia counter-attacked. Perisic raced onto a ball by Kalinic, and his angled drive beat de Gea at the near post.
- In the final seconds, Silva's shot was cleared.
The talking point
Croatia were furious with referee Bjorn Kuipers for giving Spain a penalty in the 70th minute, having had an appeal turned down five minutes earlier. Pjaca tried to take on three Spain players, and fell inside the box. But there looked to be no foul. Croatia were then at the end of a soft penalty decision. To add to the controversy, Subasic was well off his line when he saved from Ramos, and the penalty should have been retaken.
Man of the Match
Perisic. His historic winner alone is worthy of the accolade. Spain have never lost a game at the European Championship after taking the lead, and had not lost in this competition in 4,384 days. The Inter Milan winger showed great desire to race down the pitch following a counter-attack, and not many have beaten de Gea on the near post. His wing play in the 45th minute set up Croatia's equaliser and gave them a platform to get all three points.
What the result means
Croatia's reward for topping Group D is a last-16 clash with either Slovakia, or a third-placed team from Group E or F.
Spain have dropped down to second place and will face former champions Italy for a place in the quarter-finals. Hosts France, Germany and England are also on Spain's side of the draw.
Kalinic ended Spain's Euro record-breaking run without conceding at 735 minutes. He also ended de Gea's international-record run without conceding at 495 minutes.
What they said
Spain manager Vicente del Bosque: "The players were sat in silence. They don't enjoy losing. We had the game under control, I'm not going to defend our performance excessively but I think we played quite well. It was just one slip of concentration at the end, I don't have any complaints about the players."
Ramos: "Now we have to dance with the favourites, but to be champions you have to beat everyone."