Reigning European champions Spain lived to fight another day when a late Jesus Navas goal gave them an edgy 1-0 victory over Euro 2012 Group C rivals Croatia and sent them into the last eight of the tournament.
The goal that started with a piece of brilliance from substitute Cesc Fabregas, who lobbed the ball over a napping defense for Andres Iniesta to feed substitute Navas, killed off Croatia's chances of a spot in the quarter-finals.
Spain topped the group on seven points with Italy, also advancing after a 2-0 win over Ireland, on five and Croatia with four. The Irish finished with zero.
It was, however, hardly a display that world champions Spain will want to remember. "The performance as a whole was not brilliant but we dominated," said coach Vicente del Bosque.
The Croats, needing only a victory to advance and refusing to be intimidated, missed a golden chance through Ivan Rakitic early in the second half.
Defeat would have sent the Spaniards out of the tournament.
The Croats were also unlucky not to have got a penalty five minutes from time when Sergio Busquets blatantly dragged down Vedran Corluka as he was ready to head in from two meters.
Spain will now meet the runners-up of Group D, which will be France, England or co-hosts Ukraine who all play on Tuesday.
The loss also meant the end of a six-year stint for Croatia coach Slaven Bilic who will join Lokomotiv Moscow next season.
"It was a tough match and they managed to play their game as well," said Navas. "It was difficult to penetrate their defenses."
The encounter was never going to be an exhibition of skills, with the taller and stronger Croats trying to outmuscle the diminutive Spaniards.
Spain, initially sticking with forward Fernando Torres in the lineup after his two goals against Ireland, had the first chance with the 28-year-old's header in the opening minutes.
As thick black clouds gathered above the amber-tinted stadium, the Spaniards gradually found their rhythm with Gerard Pique and Torres again coming close.
With the lion's share of possession in the first half, they had control of the game, keeping their opponents constantly on the backfoot but lacked the final decisive touch to score.
"We didn't have that many options going forward but that was also down to their virtues," said Del Bosque. "Our first touch let us down at times and that robbed us of speed and intensity."
Croatia grew more positive, especially after Italy scored in the other game with the result flashed across the big screens, and Rakitic should have scored but keeper Iker Casillas blocked his header and the rebound after Luka Modric's pinpoint cross.
Bilic went for broke, throwing on forwards Nikica Jelavic, Ivan Perisic as well as Eduardo in search of the winner as fans lit flares in the stands forcing brief breaks in play for the smoke to clear.
But while Croatia demanded a penalty for the pull on Corluka, it was Spain who were rewarded when Fabregas' chip beat the offside trap and Iniesta found Navas for an easy goal.
"The game plan was to thwart Spain in the first half and have a go at them in the second," said Bilic. "It worked and we did everything right except score. We came here to go all the way and we failed because we lacked that tiny bit of luck that makes all the difference."
(Reporting by Karolos Grohmann; editing by Ken Ferris)