South Africa centre Marius Joubert scored a superb hat-trick to give his side a stunning bonus-point win over New Zealand at Ellis Park.
South Africa 40 (19)
Tries: Joubert 3, Paulse, De Villiers
Cons: Montgomery 3
Pens: Montgomery 3
New Zealand 26 (13)
Tries: Muliaina, Rokocoko
Con: Mehrtens 2
Pens: Mehrtens 4
Despite going 10-0 behind early on, the Springboks went into the break 19-13 ahead thanks to two scores from Joubert and one from Breyton Paulse.
Joe Rokocoko powered his way over to put the All Blacks ahead again but Jean de Villiers replied for the home side.
And victory was sealed late on when Joubert crossed on 76 minutes.
South Africa started the game on the back foot after giving away a succession of early penalties, allowing Andrew Mehrtens a simple penalty.
However, they bounced back and had most of the possession only for Mils Muliaina to capitalise on a mistake to cross for a powerful try on eight minutes to put his side 10-0 ahead.
Welsh referee Nigel Williams had not endeared himself to the Johannesburg crowd with his early decisions and a massive cheer went up in Ellis Park when he had to leave the field injured on 15 minutes.
The Springboks continued to have a lot of the ball and after camping on the All Black line, Joubert was sent over by number eight Joe van Niekerk for an easy score.
Paulse scored the Boks' second try
Mehrtens put New Zealand further ahead with his second penalty but South Africa went into the break 19-13 ahead thanks to two tries in two minutes at the end of the half from Paulse and Joubert.
The second half was an untidy affair with the kickers from both sides taking over.
Mehrtens and Percy Montgomery swapped penalties before flying wing Rokocoko showed his brute strength to power his way over through the desperate New Zealand defence.
With the match turning into a war of attrition, the sides again traded penalties before De Villiers stormed over to put his side 30-26 ahead with 13 minutes left.
Full-back Montgomery missed the conversion but he made amends soon after with a well-struck penalty.
And Joubert became only the second Springbok to score a hat-trick against the All Blacks when he crossed with four minutes left to send the Ellis Park crowd into raptures.
The victory now sets up a thrilling Tri-Nations finale next week when South Africa take on Australia in Durban.
South Africa: P Montgomery; B Paulse, M Joubert, D W Barry, J de Villiers, J van der Westhuyzen, B Conradie; O du Randt, J Smit (capt), E Andrews, B Botha, V Matfield, S Burger, G Britz, J van Niekerk.
Replacements: H Shimange; CJ van der Linde; AJ Venter; J Cronje; F du Preez, G du Toit, B Russell.
New Zealand: M Muliaina; D Howlett, T Umaga (capt), S Tuitupou, J Rokocoko; A Mehrtens, J Marshall; K Meeuws, K Mealamu, C Hayman, C Jack, S Maling, J Gibbes, M Holah, X Rush.
Replacements: A Hore, G Somerville, M Tuiali'i, C Newby, B Kelleher, N Evans, Aaron Mauger.