Midfielder Bernard Parker scored the early second-half winner, chipping goalkeeper Victor Valdes from close range and a desperate lunge from a defender could not keep the ball out.
Spain rarely threatened to equalise at the Soccer City stadium where they defeated the Netherlands 1-0 to win the 2010 World Cup.
The shock defeat came four months after the only other reverse for La Roja (The Red Fury) this year — a 3-0 hiding from hosts Brazil in the Confederations Cup final.
Spain brought seven of the team that started in the World Cup final and they all began against Bafana Bafana (The Boys).
South Africa included left-back Thabo Matlalba and midfielders Andile Jali and Oupa Manyisa from the Orlando Pirates side that finished runners-up to Egyptian side Al Alhy in the CAF Champions League earlier this month.
Striker David Villa had the ball in the South African net twice within seven minutes of the kick-off, but the assistant referee correctly ruled offside on each occasion.
The world champions dominated possession in the opening stages with goalkeeper Iker Casillas often the lone figure in the Spanish half.
But South Africa nearly snatched the lead on 18 minutes when a long-range Oupa Manyisa shot went over off the top of the crossbar after taking a deflection.
Parker then stung the fingers of Casillas with a snap shot that the captain could not grasp, but the ball was cleared
Other chances saw Fernando Llorente head wide off a high cross and Bongani Khumalo did likewise off a corner in first-half stoppage time.
Tokelo Rantie was wildly off target when he should have done better early in the second half after being put through by substitute Siphiwe Tshabalala.
However, South Africa went ahead 11 minutes into the second half when a couple of slick passes left Parker facing substitute Valdes.
The diminutive midfielder, who has played for Dutch, Serbian and Greek clubs, calmly chipped the ball over the shot-stopper and the ball landed in the net.
Valdes was forced to retire injured with 10 minutes left, creating a problem for Spain as they had used all six substitutes allowed.
But after touchline discussions, third-choice Pepe Reina was allowed to come on, much to the annoyance of Bafana coach Gordon Igesund.
Rantie squandered a great chance to double the lead five minutes from time as he broke clear only to allow Reina block a timid shot.