David Villa and Andres Iniesta each scored as Spain beat Chile 2-1 on Friday at the World Cup, a result that sends both teams on to the round of 16.
Villa got his goal on a shot from 45 yards out in the 24th minute, when goalkeeper Claudio Bravo came out of his area and cleared a ball straight to the Spain striker.
Iniesta doubled the advantage by beating Bravo with a right-footed shot from the edge of the area in the 37th, with Marco Estrada ejected after collecting his second yellow card on the play.
Chile didn't back down, pressing and scoring on substitute Rodrigo Millar's deflected shot in the 47th.
After starting the tournament with a stunning loss to Switzerland, Spain finished at the top of Group H with six points and will play Portugal in the next round. Chile was second and will play Brazil. Switzerland was third and Honduras was last.
"We have reacted a very difficult situation and have done well," Spain coach Vicente del Bosque said.
"There's a lot of pressure in Spain" for us to go further and "we want to do well," he said.
Villa's goal at Pretoria's Loftus Versfeld Stadium halted Chile's early momentum.
He ran on to the loose ball and curled a high, left-footed shot from just inside the Chile half into an open goal after Bravo had rushed out of the area to clear Alonso's long ball as Fernando Torres chased it down.
Later, Villa and Iniesta — returning from a right leg injury — worked the ball down the field together with Iniesta side-footing it past Bravo into the far corner.
Estrada, who was replacing the suspended Carlos Carmona, was already yellow-carded in the 21st minute and was shown a red card for tripping up Torres during the buildup to the second goal.
Chile was the first South American team to lose a match at the 2010 World Cup.
"I think that we deserved to advance because of the two previous matches," said Chile midfielder Rodrigo Millar. Chile beat Switzerland and Honduras and lost to Spain in the group on tiebreakers.
"We now have a difficult match against Brazil in the next round. We know we're going to face one of the biggest teams in the world."