It was not until fullback Jordie Barrett kicked his fourth penalty with two minutes left on the clock that the All Blacks took the lead for the final time.
New Zealand have narrowly justified their number one world ranking with a hard fought 19-17 win over world champions South Africa in Townsville to win the Rugby Championship title with a match to spare.
The 100th test between rugby's two most successful nations did not disappoint and it was not until fullback Jordie Barrett kicked his fourth penalty with two minutes left on the clock that the All Blacks took the lead for the final time.
All Blacks winger Will Jordan and his Springboks counterpart S'bu Nkosi scored early tries but from then on a match of high intensity came down to a kicking duel between South Africa flyhalf Handre Pollard and Barrett.
Although the All Blacks were unable to indulge in the free-running that usually characterises their game, Barrett's 14 points from the tee were enough to give them a 12th southern hemisphere test championship title and a 10th successive win.
"The performance was not what we wanted, we were forced into a lot of errors because of the pressure (but) we showed a determination to keep fighting and got there in the end," said All Blacks coach Ian Foster.
"It's really significant for us. The 100th, the history between us, they are a team we respect greatly. Hats off to Jordie for that last kick."
After disappointing in back-to-back losses to Australia over that cost them the number one spot in the rankings, the Springboks were back to their powerful best at North Queensland Stadium.
Scrumhalf Faf de Klerk sent box kick after box kick into the Townsville sky and his forwards muscled up in the tight and at the set piece.
The All Blacks scored first in the third minute when hooker Codie Taylor latched onto a loose ball and found room to burst up the middle before finding Jordan in support with a clear sprint to the line.
The Springboks hit back almost immediately with All Blacks winger George Bridge losing a de Klerk bomb in the evening sky and Nkosi pouncing to touch down.
🇿🇦 A much-improved performance by the Boks, but in the end the All Blacks have snatched a 19-17 victory in a humdinger in Townsville. #StrongerTogether #StrongerForever #NZLvRSA pic.twitter.com/qYUdFSJ2Lu— Springboks (@Springboks) September 25, 2021
Two Handre Pollard penalties gave South Africa an 11-7 lead after 13 minutes but Jordie Barrett put the All Blacks back in front with two of his own, the second after Nkosi had been sent to the sin bin for a deliberate knock down.
New Zealand held the 13-11 halftime lead until Pollard's third penalty just before the hour mark but Barrett was quickly able to restore the slender advantage.
Another penalty after the collapse of a rolling maul allowed Pollard to put South Africa 17-16 in front in the 67th minute – a sixth change of lead – but Barrett was unerring when his chance came to snatch the win from 40 metres out.
"I thought it was a proper test match between the number one and the number two teams in the world," said Springboks coach Jacques Nienaber, who was already looking forward to next week's return match on the Gold Coast.
"It came down to wire, a call here, a bounce of the ball there, sometimes it goes for you and sometimes it goes against you."