(CNN) -- Spain have drawn level with Brazil's record by going 35 matches unbeaten, after second-half goals from David Villa and Fernando Llorente gave them a 2-0 Confederations Cup victory over host nation South Africa in Bloemfontein.
The South African players appeal for handball as David Villa celebrates Spain's opening goal on Saturday.
The result ensures the European champions comfortably reach the semifinals of the competition as group winners, while South Africa also progress to the last four after New Zealand and Iraq draw 0-0 in Saturday's other Group A match in Johannesburg.
Vicente Del Bosque's side were last beaten in November 2006 and they will better Brazil's unbeaten streak, achieved between 1993 and 1996, if they win Wednesday's semifinal.
Spain have also drawn level with Australia, Brazil and France in winning 15 consecutive matches and victory on Wednesday will ensure they break that record as well.
After a goalless first half, the match exploded into life five minutes after the interval when Spain's Cesc Fabregas was crudely fouled in the area by Aaron Mokoena, who has just signed a contract with Portsmouth and has regularly faced the Arsenal midfielder in the English Premier League.
In-demand Valencia striker David Villa stepped up to take it, but his spot-kick was superbly pushed away by goalkeeper Itumeleng Khune, diving to his right.
However, South African joy was short-lived as just a minute late Villa again showed what a class player he is when turning superbly to fire home Albert Riera's inch-perfect through-ball.
The South African players claimed Villa controlled the ball with his arm before burying it into the far corner and TV replays seemed to indicate they had a valid argument for the goal to be disallowed.
Villa's strike was his 31st goal in 47 international appearances, putting him just 13 off Raul Gonzalez's all-time Spanish record.
Spain, who look a class apart in this tournament and have qualified after winning all their three games without conceding a goal, secured the three points in the 71st minute when substitute Fernando Llorente turned the ball home in a crowded goalmouth, after Xavi's low free-kick from the right had been helped on by a Fabregas mis-kick.
Despite the defeat, South Africa's participation in the tournament remains very much alive after Iraq and New Zealand played out a dull stalemate.
A two-goal Iraq victory would have seen the host nation crash out, but the result was no great surprise as neither side managed to score a single goal in their three matches.
Sunday sees the remaining Group B matches played, with Italy and Mexico battling it out to seemingly join Brazil in the last four. However, no team is absolutely certain of qualification yet and all four sides in the group can still in theory go through.
Brazil face Italy in Pretoria and a draw will see the Brazilians definitely finish top of the group.
However, an Italian victory will then turn the attention to the other match between Egypt and the United States in Rustenburg.