كتب : Hatem Maher
South Africa, who had four points and needed a draw to ensure their progress, were defeated by second-half goals from David Villa and substitute Fernando Llorente.
They managed to book a last-four berth nevertheless after Iraq, who had one point, failed to overcome New Zealand.
European champions Spain, who qualified as Group A leaders after getting maximum points from three games, set a new record.
They chalked up their 15th successive win to surpass the mark they shared with Australia, France and Brazil.
They also stretched their unbeaten run, which dates back to November 2006, to 35 games to equal Brazil's record.
Spain laid siege to South Africa's area for the majority of the first half but struggled to create clear-cut opportunities.
Albert Riera had a powerful free-kick tipped over by South Africa keeper Itumeleng Khune after four minutes.
Spain's best chance fell to Fernando Torres ten minutes before the break.
A deft Cesc Fabregas pass broke the offside trap and found the Liverpool striker, whose attempted chip was thwarted by Khune.
South Africa's counter attacks late in the first half did not really trouble Spain keeper Jose Reina.
Amends
Villa had a chance to break the deadlock on 51 minutes when Spain were awarded a penalty after Aaron Mokoena's clumsy challenge brought down Fabregas inside the area.
The Valencia marksman stepped up but the in-form Khune dived the right way to block his effort.
He made amends just one minute later in superb fashion as he brilliantly controlled Riera's chipped pass before sending a delicate left-footed shot past the unlucky Khune.
Villa took his tally to 31 goals with Spain, 13 short of the team's all-time top scorer Raul.
Llorente, who replaced Torres on the hour mark, ensured Spain's victory in the 72nd minute when he converted Fabregas' mis-hit shot from close range after a low cross from Xavi.