(CNN) -- Spain's World Cup campaign finally burst into life as they beat ten-man Chile to finish top of Group H and avoid a last 16 clash with tournament favorites Brazil.
David Villa and Andres Iniesta scored the goals as the European champions leapfrogged their opponents into top spot courtesy of a 2-1 win.
Switzerland failed to take advantage of Chile's defeat and grab the last qualification spot, as their game with Honduras finished 0-0.
Spain will now face Portugal in the second round while Chile will play Brazil.
Spain 2-1 Chile
Spain headed into the game knowing that a win would be good enough to take them into the second round as group winners.
Liverpool striker Fernando Torres had an early chance to put them in front but he headed over from Xavi's cross.
Chile's first chance came in the tenth minute when Jean Beausejour crossed for Mark Gonzalez but the winger couldn't direct his effort on target.
In the 24th minute Barcelona striker David Villa broke the deadlock.
As Fernando Torres raced to latch onto a long pass, Chile 'keeper Claudio Bravo rushed out of his goal to clear, but Villa latched onto the loose ball to stroke it into the net.
Defender Gerard Pique should have made it 2-0 when he put a free header over the bar from ten yards out, but he had to be alert seconds later to deny Beausejour an equalizer.
Then came the decisive passage of the game as Villa squared for Andres Iniesta to place a shot into the corner. In the build up to the goal Chilean defender Marco Estrada tripped Torres and was sent off after being shown a second yellow card.
Chile's ten men did hit back within minutes of the restart as substitute Rodrigo Millar's shot deflected off Pique and into the net but they failed to create any chances after that.
There was a worry for Spain as striker Torres was substituted on 55 minutes. The 26-year-old was injured at the end of the Premier League season with Liverpool and began Spain's opening game on the bench.
Chile pushed forward in search of an equalizer late on but Spain made their extra man count to retain possession, kill off the game and secure top spot.
Switzerland 0-0 Honduras
Switzerland knew they had to beat Honduras to have a realistic chance of going through through but it was Honduras who enjoyed the majority of possession in the early stages.
Midfielder Gokhan Inler squandered Switzerland's first opportunity, shooting wide form the edge of the penalty area.
Striker Eren Derdiyok then headed wide from six yards out after meeting Stéphane Grichting's right wing cross but the teams went in level at the break.
With Chile trailing to Spain, Switzerland poured forward in search of the goals that would have lifted them into second spot and meant qualification for the last 16.
But it was Honduras who had a glorious chance to take the lead just after half-time when Edgar Alvarez's cross found David Suazo unmarked six yards from goal but the striker somehow managed to put his header wide.
Then only a brilliant reaction save from Switzerland 'keeper Diego Benaglio prevented Edgar Alvarez from scoring as Honduras broke quickly.
Switzerland's Alexander Frei was next to go close as he met Hakan Yakin's free-kick at the far post but he couldn't direct his effort on target.
Both teams threw players forward to try and find a winner but it ended 0-0.