New Zealand 31 (21)
Tries: Rokocoko (2), MacDonald, Mealamu
Con: MacDonald (3) McAlister
South Africa 27 (17)
Tries: Habana, Januarie, Fourie
Cons: Montgomery (3)
Pens: Montgomery (2)
New Zealand kept their Tri-Nations title chances alive with a thrilling victory over South Africa in Dunedin.
A South African win or draw would have given the Springboks the crown.
But the title will now be decided in Auckland on Saturday, when New Zealand will become champions if they beat Australia in the series' final match.
The lead changed hands five times in the match, but New Zealand hooker Kevan Mealamu crossed for the decisive try five minutes from time.
Winger Joe Rokocoko scored twice for the All Blacks to signal a return to top form.
His first came in the early minutes, when centre Aaron Mauger charged down Andre Pretorius' kick and Rokocoko gathered and sped away from the South African defence.
Yet the advantage was lost almost immediately, as Bryan Habana - a sensation for South Africa throughout the Tri Nations - found space on the left after New Zealand lost the ball in the ruck.
Percy Montgomery added the extra points, but after 20 minutes he erred to hand the initiative back to the All Blacks.
Under pressure from Richie McCaw, he failed to grasp Mauger's high ball, and Mealamu charged forward, setting up fly-half Leon MacDonald to score under the posts.
Rokocoko then exploited weak tackling to bulldoze through after picking up the loose ball from a ruck five metres out and score his second try.
Springbok fortunes changed within seconds of half-time.
Piri Weepu cleared the ball to MacDonald but a quick-thinking Ricky Januarie charged down his clearance to record five valuable points.
The momentum was suddenly with the Springboks, and Januarie was again the inspiration minutes later, intercepting a stray Jerry Collins pass and feeding Jaque Fourie to score under the posts.
New Zealand coach Graham Henry responded by replacing MacDonald with Luke McAlister, as well as changing both his props.
And with the title slipping away, New Zealand stepped up the pace.
With five minutes to go, their forwards drove to the line from a lineout, and Auckland hooker Mealamu hung back, split from the maul and plunged over the line.
Blues team-mate McAlister converted to give the All Blacks a decisive advantage.
All Blacks skipper Umaga admitted his side had been slightly fortunate to win.
"We were lucky to hold them out and get what we got, but we're happy with it," Umaga said.
"To the Springboks' credit, they never gave up, as you saw on the scoreboard and in the way they played.
"We created a lot of things again and again they lived off our mistakes. It's the way they've been playing and it's obviously successful for them."
South Africa skipper John Smit praised his battling side despite their defeat.
"We knew it was going to be tight and although we lost, it was a good performance by the boys," he said.
"We spent a little bit too much time in our half, which cost us in the end. It was a very tough game."
The defeat ended South Africa's 100% record in this season's Tri Nations and means New Zealand can clinch the title if they beat Australia on Saturday.
South Africa still head the standings with 13 points from four matches, but the All Blacks have 10 points from three games and can top the table if they gain four points for a win against Australia.
South Africa's defeat extended their winless run in Dunedin to seven matches, stretching back to 1921.
New Zealand: Mils Muliaina; Rico Gear, Tana Umaga (captain), Aaron Mauger, Joe Rokocoko; Leon MacDonald, Piri Weepu; Tony Woodcock, Keven Mealamu, Carl Hayman, Chris Jack, Ali Williams, Jerry Collins, Richie McCaw, Rodney So'oialo.
Replacements: Derren Witcombe, Greg Somerville, James Ryan, Sione Lauaki, Kevin Senio, Luke McAlister, Doug Howlett.
South Africa: Percy Montgomery; Jean de Villiers, Jaque Fourie, De Wet Barry, Bryan Habana; Andre Pretorious, Ricky Januarie; Os du Randt, John Smit (captain), CJ van der Linde, Bakkies Botha, Victor Matfield, Schalk Burger, Juan Smith, Joe van Niekerk.
Replacements: Hanyani Shimage, Eddie Andrews, Albert van den Berg, Jacques Cronje, Fourie du Preez, Jaco van der Westhuyzen, Marius Joubert.