In the most extraordinary one-dayer ever, the home side's victory was achieved with one ball to spare and sparked wild celebrations on and off the Wanderers pitch.
Before Sunday, no side had scored more than 400 in a one-day international and South Africa's total topped Australia's record 434 for four earlier in the day.
Two players, Australian captain Ricky Ponting (164) and South African Herschelle Gibbs (175), scored over 150 in the fifth one-dayer.
A total of 872 runs were scored. The previous record was 693 when India beat Pakistan by five runs in Karachi in March 2004.
The previous innings record was the 398 for five Sri Lanka scored against Kenya in Kandy in 1995-96.
World champions Australia had been 2-0 down in the series, suffering a record 196-run loss in the second match, before drawing level at 2-2.
After winning the toss and choosing to bat, Ponting reached his century off 73 balls. In all he faced 105 deliveries, hitting 13 fours and nine sixes.
Gibbs then kept the home side up with the required scoring rate by blazing 175, including seven sixes, off 111 balls. Captain Graeme Smith also scored 90, putting on 187 for the second wicket with Gibbs.
Gibbs's was the second highest score by a South African after Gary Kirsten's 188 not out against the United Arab Emirates at the 1996 World Cup.
Ponting is the first Australian to reach 9,000 runs in one-day internationals and his innings was the third highest by an Australian.
The two batsmen were jointly awarded man of the match but Ponting declined it, saying Gibbs deserved the honour alone.