David Villa had two early goals chalked off for offside, but South Africa just edged a tight first half as the sides went in 0-0.
After the break the hosts' pressing game continued and they took a deserved lead through Bernard Parker's lob, and his side were able to hold on for a big win.
Here, Sports Mole analyses whether the result was justified or not.
On target 3
On target 5
Was the result fair?
Yes. Spain, of course, had the vast majority of the ball, but the better chances fell to the hosts. It turned into a game that was always likely to be won by a single good chance and it was South Africa who converted theirs. The home defence restricted Spain for most of the game and on the break they looked capable of opening up their opponents on a number of occasions.
South Africa's performance
It was a case of a gameplan being acted out to perfection for South Africa. The aim was to keep things tight, press in midfield and break at pace, all of which they managed to do for 90 minutes. Even though they had fewer shots overall and less of the ball, they were far more clinical with the possession that they did have.
This was a long way from the Spain that cruised their way to the World Cup three-and-a-half years ago. It was the lack of movement from the attacking three that stood out, as despite the midfield seeing a lot of the ball they could not convert this into genuine chances. Indeed, their best effort came in second-half stoppage time as they chased the game.
Sports Mole's man of the match
Bernard Parker: South Africa's top scorer in their unsuccessful World Cup qualifying campaign was their most dangerous player against the holders. He led the line with movement into the channels and deep into midfield all game long and was able to cap his performance with the winner in the second half.
While it was a game of little quality overall, there were also not many mistakes. The biggest error of the game has to be Tokelo Rantie's, when he slashed a really good chance high and wide after being put through by Siphiwe Tshabalala. He was fortunate that it ended up not being costly.
South Africa: Tonight's hosts are done for the year and with no preparation for the World Cup they have a series of home friendlies in the new year, starting with Mozambique in January.
Spain: There are no further games in 2013 for Spain either, but they face European opposition at home in Macedonia in February to begin their World Cup preparations.