Ian Foster may have been given a lifeline at Ellis Park as New Zealand stopped the rot with a thrilling 35-23 Rugby Championship win over South Africa.

All Blacks head coach Foster has faced huge pressure after a dismal run of five defeats in six Tests, but his side appear to be behind him on the evidence of their impressive performance in Johannesburg on Saturday.

They opened up a 15-point lead following tries from captain Sam Cane and Samisoni Taukei'aho, but the world champions fought back to take the lead with 12 minutes to go courtesy of scores from Lukhanyo Am and Makazole Mapimpi, as well as 15 points from the trusty boot of Handre Pollard.

New Zealand were also a man down with Beauden Barrett in the sin bin, but late tries from David Havili and Scott Barrett stunned the Springboks to deliver a vital victory.

Richie Mo'unga scored 15 points from the tee as the holders secured a battling victory for the under-fire Foster.

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.