Substitute Jesus Navas tapped home two minutes from time to snatch a 1-0 victory over Croatia and send holders Spain through to the last eight of Euro 2012 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.
Spain topped the group on seven points, with Italy on five and Croatia on four, while Ireland finished with zero.
Spain's late winner was tough on Croatia and they probably had the best chance of the game before Spain's goal when Iker Casillas brilliantly blocked Ivan Rakitic's close-range header in the 59th minute.
Image: Spanish players celebrate the only goal during the Euro 2012 soccer championship Group C match between Croatia and Spain in Gdansk, Poland, Monday, June 18, 2012.