Two Jordie Barrett pressure kicks in the 74th and 78th minutes, a superb dropped goal by replacement first five-eighths Elton Jantjies followed by his injury time penalty goal, was a salve for much of the angst the Springboks had drawn for most of the winter.
It was a much befitting the rivalry between the sides, the 101st Test between the two, and it was based on Springbok forward power, a domination of the lineout with several All Blacks mistakes proving costly.
And in the final instance, with the win in the bag, New Zealand conceded a turnover penalty in South Africa's half. A powerful blast by fullback replacement Frans Steyn resulted in a lineout on the 22m line and the All Blacks conceded a penalty out from their own line and that gave Jantjies his chance.
While New Zealand scored three tries to two, there was no dispute with the Springbok intent, led by lock Eben Etzebeth's lineout display and power in the backline from second five-eighths and first try scorer Damian de Allende while Steyn's introduction for the unfortunate Willie le Roux was a key choice with his power kicking a useful weapon.
South Africa showed more positivity in the first quarter to dominate possession, but their best opportunities for tries were lost when le Roux twice kicked for position when players had opportunities outside him.
One kick did provide a chance for hooker Bongi Mbonambi, but he grounded the ball just short of the line and the All Blacks were able to clear, and then set about dominating the second quarter. Able to lift the speed of the game, and negate the opportunities for South Africa to bring on their medics, by quick throw-ins and use of long kicks to gain put-ins from return kicks.
The toll of the faster play was acknowledged when Springboks coach Jacques Nienaber replaced his front row two minutes before halftime.
Gaining a turnover via skipper and flanker Ardie Savea after Akira Ioane's tackle on Bok captain and flanker Siya Kolisi proved fruitless as they attempted to run the ball out from their 22m area. Hooker Codie Taylor in midfield, couldn't take the ball, the Springboks pounced and centre Lukhanyo Am's backhand pass found wing S'busiso Nkosi who fed second five-eighths Damian de Allende in at the corner.
No sooner had first five-eighths Handré Pollard landed a penalty goal than le Roux dropped the restart and Savea picked it up and set the play in motion for ruck ball to be presented for first five-eighths Beauden Barrett to lob a kick to the corner where wing Sevu Reece took the ball and scored in No8 Duane Vermeulen's tackle.
Capitalising on a quick throw in their own 22m area, after le Roux's second kick to the line, allowed the All Blacks to throw long at a lineout. Akira Ioane won the ball, and Beauden Barrett stepped through the line and found Rieko Ioane. He ran hard, broke tackles and then had Savea in support for the try in the 27th minute.
Five minutes later they extended their lead from a lineout after Jordie Barrett ran a Springbok kick back downfield which with ball on the left flank for centre Anton Lienert-Brown to run at the line, only to be dropped in a fine cover tackle by Nkosi. However, in the lineout Scott Barrett upset the ball and when it dropped on the Springbok side of the line halfback Brad Weber slipped through to grab the ball and score.
South Africa brought on Frans Steyn for de Klerk at halftime, and his powerful punting pushed New Zealand back and from his second effort, the lineout ball set up a strong drive with replacement hooker Malcolm Marx driving hard and as the ball was moved, it was wing Makazole Mapimpi who went in at the corner.
Ending their three-game losing streak the world champions showed great resolve and could claim a deserved win. Although the All Blacks unbeaten season was disrupted, they still walk away as holders of the Freedom Cup and winners of the Fortinet Rugby Championship.
The All Blacks next clash is against USA in Washington on October 24 to start their Northern Tour.
Scorers: New Zealand 29 (Sevu Reece, Ardie Savea, Brad Weber tries; Jordie Barrett con, 4 pen) South Africa 31 (Damian D'Allende, Makazole Mapimpi tries; Handré Pollard 4 pen; Elton Jantjies 2 pen, dropped goal). HT: 20-14