© Getty Images
Soccer City played host as Vicente del Bosque's men revisited the scene of their 2010 World Cup final victory over the Netherlands.
However, the international giants experienced contrasting fortunes as Bernard Parker's 56th-minute strike proved sufficient in earning his nation its first win over La Roja.
La Roja grew stronger as the half went on, with Fernando Llorente in particular proving a menace for Bafana Bafana's rearguard.
The Juventus striker rose highest to meet a Pedro cross, but his headed effort flew over the bar.
South Africa boss Gordon Igesund nearly saw his team take the lead on the stroke of half time, when Parker should have opened the scoring but the 27-year-old headed narrowly wide from a corner.
The Kaizer Chiefs marksman would make amends, though, firing the hosts into the lead by clipping over Victor Valdes - a second-half substitute - 11 minutes into the second half.
With Spain vulnerable to attack, South Africa went in search of a second and nearly found it through Parker once more, but the striker's stinging effort was blocked.
The visitors came close to restoring parity in the dying stages, only for Santi Cazorla to see his 20-yard strike well saved by goalkeeper Itumeleng Khune and South Africa held on for a historic victory.