Scott Barrett and Ardie Savea scored late tries as Rugby Championship winners New Zealand gained sweet revenge over South Africa by pulling off a rousing fightback to snatch a 32-30 victory in Pretoria.

The Springboks pulled off a shock first win over the All Blacks in New Zealand for nine years last month, edging a classic in Wellington 36-34.

Rassie Erasmus' side looked set to pull off a famous double in the final match of the tournament, but the All Blacks rallied from 30-13 down with 20 minutes to play to finish on a high note at Loftus Versfeld Stadium.

South Africa, roared on by a raucous crowd, dominated the first half but two Beauden Barrett pegged them back at 6-6 at the break after Handre Pollard was on target twice from the tee.

Tries from Jesse Kriel and Damian de Allende early in the second half put the hosts in command and Cheslin Kolbe added a third after Aaron Smith had touched down at the other end, Pollard taking his tally with the boot to 15 points.

The world champions had been outplayed for much of an absorbing contest, but they left South Africa breathless at altitude when Rieko Ioane's score was followed by Scott Barrett going over four minutes from time and Savea driving over in the final minute, Richie Mo'unga duly landing his third conversion to win the match.

New Zealand had not lost a Rugby Championship game since 2015 before their loss to the Springboks on home soil and a late rally ensured they did not go down twice in the space of three weeks.