Substitute Jesus Navas scored a late goal to send Spain through to the Euro 2012 quarter-finals as Group C winners but only after a mighty scare as they beat Slaven Bilic's unfortunate Croatia 1-0.
Mario Mandzukic and Ivan Rakitic both had earlier chances to break the deadlock and Croatia kept pushing deep into injury-time as they sought the equaliser that could still have sent them through.
Resolute in defence and surging down the flanks on the counter-attack, Croatia kept the Spaniards at bay for long periods and Vicente Del Bosque's team will be extremely relieved to have come out on top of their group thanks to Navas' close-range finish.
In a poor first period, Fernando Torres came closest to breaking the deadlock when he brought a good save out of Croatia goalkeeper Stipe Pletikosa in the 23rd minute.
But after Gerard Pique shot over the bar, Croatia replied with some pressure of their own, Danijel Pranjic shooting low at Iker Casillas and Mandzukic blazing over the bar from just inside the box.
Croatia had a loud penalty appeal turned down in the 27th minute when Mandzukic's charge down the right flank was brought to an end by a crashing challenge from Sergio Ramos on the edge of the box, but referee Wolfgang Stark waved Croatian appeals away.
Knowing they were likely to need a goal to give them a chance of reaching the last eight, Croatia made a brighter start to the second half with a dangerous corner from Rakitic punched away by Casillas.
And Croatia came agonisingly close to taking the lead in the 59th minute when Luka Modric beat Ramos on the right and crossed into the box where Rakitic's low header was brilliantly saved at point-blank range by Casillas.
Perhaps shaken by the near-miss, Del Bosque responded by replacing the ineffective Torres with winger Navas, as his side sought desperately to regain control of the game.
Fellow substitute Cesc Fabregas was having a major influence in calming Spanish nerves and he made the crucial move in the 87th minute when he lobbed Pletikosa to send Anders Iniesta clear, and he squared for substitute Navas to tap home the simplest of chances.
Comments: Our rules
We want our comments to be a lively and valuable part of our community - a place where readers can debate and engage with the most important local issues. The ability to comment on our stories is a privilege, not a right, however, and that privilege may be withdrawn if it is abused or misused.
Please report any comments that break our rules.
Read the rules here