South Africa lost Damian Willemse to the sin bin for a ruck infringement early on and Jesse Kriel was unable to return after a head injury assessment, but they prevented New Zealand from scoring when they were a man down.
A scrappy Test burst into life after Mo'unga's 25th-minute penalty, as Cane finished in the corner following an incisive break from Caleb Clarke and Taukei'aho crashed over for a try that Mo'unga converted brilliantly.
The Springboks quickly reduced the arrears when Am showed power and pace to round off a slick move on the right wing and Pollard cut the gap to five points with a mammoth penalty on the stroke of half-time.
Mo'unga was on target again after Pollard's second successful penalty early in the second half and the All Blacks fly-half put his side eight points up when he sent another kick between the posts after Mapimpi had a try disallowed for obstruction.
Mapimpi was not to be denied moments later, though, taking a brilliant pass from Willemse and touching down for a score that Pollard expertly converted from the left touchline.
Pollard booted the Springboks into the lead for the first time with 12 minutes to go after replacement Beauden Barrett was yellow-carded for obstructing Jaden Hendrikse.
New Zealand dug deep to win it despite being a man down. with Havili going over in the corner following a brilliant break started by Rieko Ioane and Scott Barrett putting the icing on the cake from close range - with Mo'unga adding the extras for both scores.
All Blacks show fight for Foster
Three consecutive defeats saw New Zealand plummet to fifth in the world rankings after losing their Rugby Championship opener last weekend, their lowest point in history.
Foster may yet still pay the price for that slump, but his players might have bought him some time by lifting the Freedom Cup, having showed South Africa and the rest of their rivals they can still take the fight to them.
Savea stands up yet again
New Zealand still look fragile in defence, but there were some outstanding performances in a huge victory.
Ardie Savea stood out once again, making 13 carries and gaining 58 metres as he relished the battle with the Springboks.