European champions Spain set up a mouthwatering last-16 showdown with Cristiano Ronaldo's Portugal after seeing off 10-man Chile in a hard-fought encounter in Pretoria tonight.
Chile, who had started the day with a three-point lead in Group H, surrendered top spot to the Spanish but still qualified for the knockout stages, where they will now face Brazil.
David Villa put Spain ahead with a long-range shot into an empty net after Chile goalkeeper Claudio Bravo had raced out of his area, and Andres Iniesta doubled his side's lead towards the end of the first half.
An incident in the build-up to that Iniesta goal also resulted in Chile having a player sent off with midfielder Marco Estrada earning a second yellow card after clipping Fernando Torres' heels.
There looked little intent on Estrada's part, but the second booking left Chile with a mountain to climb.
Marcelo Bielsa's side pulled a goal back at the start of the second period through substitute Rodrigo Millar's deflected effort, but it was not enough and they will now need to overcome the Brazilians if they are to continue their World Cup adventure.
Spain, looking to avoid joining fellow big guns Italy and France in suffering a shock early exit, started well and Torres had two good chances in the opening five minutes, although the Liverpool striker could not make the most of either.
The game then swung Chile's way as the in-form South Americans lived up to Bielsa's pre-match assurance that they would not go out looking for the draw.
Mark Gonzalez skied a promising opportunity over, while Alexis Sanchez earned a corner out of Iker Casillas with a delicate chip.
However, it was Spain who took the lead in the 24th minute when Villa took advantage of some reckless goalkeeping from Bravo to put his side ahead with a brilliant finish.
There appeared little need for Bravo to race out of the area and although he beat Torres to a through-ball, the Real Sociedad goalkeeper's clearance went straight to Villa, who lofted the ball into an empty net from 40 yards out and near the left touchline.
Barcelona's new £40million striker, who scored a brace in the 2-0 win over Honduras and also missed a penalty, now has 41 goals for his country and is just three behind the national record held by Raul.
Chile briefly threatened an equaliser through Beausejour, Gerard Pique getting back to make a superb block, but then came the incident that put Spain completely in the ascendency, taking a 2-0 lead and also seeing Chile reduced to 10 men.
A good sweeping move resulted in Villa laying the ball back to his new club-mate Iniesta on the edge of the box, and the Barca midfielder coolly slotted into the far corner of the net.
And as the Spain players raced away to celebrate, Mexican referee Marco Rodriguez sent off Estrada for his innocuous-looking tangle with Torres, who was left lying on the ground on the edge of the area.
Spain could hardly have been in a better position at the interval, but they saw their two-goal advantage halved just two minutes into the second half.
Chile, having made two changes at the break, needed a good start and they got just that when one of the newcomers scored.
Millar found space on the edge of the area and fired in a shot that took a huge deflection off Pique before looping past Casillas and into the net.
That was a huge boost for Chile, but they could make no further inroads and created little to worry Casillas in the remainder of the half.
Vicente Del Bosque's Spain also created few goalscoring chances of their own, but they did not need to and looked content just to keep hold of their lead as they secured a showdown with Iberian rivals Portugal on Tuesday.