Substitute Jesus Navas tapped home two minutes from time to snatch a 1-0 victory over Croatia and send holders Spain through to the quarter-finals of the Euro 2012 football championships as Group C winners.
Croatia, who battled hard against the world and European champions, went out as Italy finished second thanks to a 2-0 win over Ireland.
Spain will now face the runners-up in a Group D featuring France, England, Ukraine and eliminated Sweden, while Italy will play the winners of Group D, which France currently top.
Spain topped the group on seven points, with Italy on five and Croatia on four, while Ireland finished with zero.
The final group D matches take place tomorrow morning, with France to play Sweden and England taking on Ukraine.