A tight and tense encounter in Queensland was settled when Barrett slotted through the posts with barely a minute remaining, a late error in possession from the Springboks then allowing New Zealand to hoof the ball into touch.
The 100th Test match between these teams started in positive fashion for New Zealand, Will Jordan touching down and Jordie Barrett converting after five minutes, but South Africa promptly turned the game on its head through S'busiso Nkosi's try and two Handre Pollard penalties.
Ian Foster's men, 23-13 winners over the Boks at the Rugby World Cup two years ago, found it hard to maintain any rhythm with the ball but did scrape into a half-time lead through two further Jordie Barrett kicks while Nkosi was sin-binned.
A topsy-turvy, error-strewn contest continued when Pollard and Jordie Barrett exchanged penalties in the space of three minutes, but it seemed South Africa's number 10 might have secured a surprise win to banish thoughts of back-to-back losses to Australia when he kicked them into a 17-16 lead with his fourth three-pointer 14 minutes from time.
Yet it was Jordie Barrett who had the final say, squeezing his penalty just inside the left-hand upright to extend the All Blacks' winning streak to 10 and secure the trophy with a game to spare.