A late goal from substitute Jesus Navas snatched Spain a 1-0 win over Croatia and confirmed the defending champions' place in the Euro 2012 quarter-finals.
Spain were on course to qualify for the last eight on goal difference but Navas's 88th-minute winner sent them through as Group C winners.
A victory for Croatia could have sent Vincente Del Bosque's side out and they came closer to an opener before the deadlock was eventually broken.
Ivan Rakitic's second-half header was superbly stopped by Iker Casillas after Luka Modric had found his teammate unmarked at the back post with an inviting cross.
Casillas also saved well from Ognjen Vukojević when he denied the midfielder, who had volleyed goalwards following Mario Mandzukic's lofted pass.
Fernando Torres, who was substituted midway through the second period, came close for the Spaniards, but his powerful shot from a tight angle was parried clear by Stipe Pletikosa.
For all of their possession, Spain failed to create many clear-cut chances throughout the first 45 minutes as defensive pair Sergio Ramos and Gerard Pique tried ambitious efforts from range.
In the second period, Andreas Iniesta and Navas tested Pletikosa more thoroughly before Navas finally ended the stalemate when he beat the offside trap before converting into an empty net.