Set to make 448 to win, Australia were bowled out for 216 after South Africa claimed the extra half hour with Australia seven down at the scheduled close.
South Africa took four top order wickets for four runs shortly after tea to swing the game in their favour. Fast bowler Dale Steyn took four of the wickets that fell after tea to finish with four for 55.
Chris Rogers and David Warner put on 126 for the first wicket, scoring at more than four runs an over and Rogers then fought a lone battle before being ninth man out, run out for 107.
Part-time off-spinner JP Duminy made the breakthrough when he trapped Warner leg before wicket for a sparkling 66, made off 73 balls.
The scoring rate slowed but Australia still looked comfortable at 141 for one at tea.
Alex Doolan struggled for more than an hour, scoring only five runs off 43 balls before he was caught at first slip off Morne Morkel.
Shaun Marsh, who made 148 and 44 in the first Test in Centurion, was out first ball, trapped in front by a full delivery from Vernon Philander.
It completed a "pair" for the left-hander, who faced only two balls in the first innings.
Steyn claimed the key wicket of Australian captain Michael Clarke, who edged a catch low to second slip, where Faf du Plessis held a good catch, tumbling to his right.
Steyn, who was gaining reverse swing, had Steve Smith leg before with a full delivery which swung in to the right-hander.
Ten runs later Steyn's fast reverse swing sent Brad Haddin's middle stump flying.
Mitchell Johnson stayed long enough to see Rogers to his century but became a fourth lbw victim. Philander's appeal was turned down by umpire Richard Illingworth but South Africa sought a review which showed the ball was hitting leg stump.
Rogers, who scored only ten runs in his first three innings of the series, looked in good touch from the start of his innings, taking advantage of some over-pitched deliveries early on and almost keeping pace with Warner during what was easily the most productive opening partnership by either side during the series.
Rogers reached his fifty off 95 balls. He could have been out in the last over before tea. On 69, he prodded at a ball from Steyn, who appealed loudly as it went through to wicketkeeper AB de Villiers.
Umpire Kumar Dharmasena gave Rogers not out and the slips cordon led by captain Graeme Smith were uncertain and did not seek a review. Replays showed the ball probably clipped the toe end of the bat.
Ryan Harris was leg before to Steyn in the first of the extra overs and Rogers was then out to a direct hit from mid-off by substitute fielder Alviro Petersen, trying to keep the strike.
With the umpires having looked at their light meters, South Africa used spin from both ends and left-armer Dean Elgar finished the match when Lyon was given out leg before. There were a maximum of 14 balls remaining in the day - and a forecast of rain for Monday.
South Africa were without injured left-arm fast-medium bowler Wayne Parnell but captain Graeme Smith juggled his bowlers well and made good use of his part-time spin bowlers.
Hashim Amla completed his 21st Test century - and his fifth against Australia - and finished on 127 not out when Smith declared at 270 for five. South Africa added 78 runs in 17 overs on Sunday. Quinton de Kock (34) was the only batsman dismissed.
Amla, who was 93 not out overnight, hit 16 boundaries in a 176-ball innings. His tally of five hundreds against Australia equalled a South African record shared by Eddie Barlow, Graeme Pollock, Jacques Kallis and AB de Villiers.