All-action skipper Richie McCaw snatched victory for New Zealand late on against South Africa after a pulsating spectacle in Johannesburg.

With the All Blacks 20-17 down - and staring at a second successive defeat to the Springboks for the first time in six years - McCaw outwitted South Africa's lineout and darted over to send the reigning world champions on to a 27-20 triumph.

For so long the Boks, who scored tries through full-back Willie le Roux and centre Jesse Kriel, looked strong but now their Rugby Championship bid is in tatters after back-to-back defeats.

Steve Hansen's All Blacks toiled for long periods, but their perseverance paid off as Ben Smith scored a vital try on the stroke of half-time before scores from Dane Coles and McCaw clinched the win.

Lima Sopoaga was preferred to Beauden Barrett at 10 for the All Blacks and the debutant settled his nerves with an early penalty amid a breathless start at Ellis Park.

With the two top-ranked teams going head-to-head - at the same venue the Boks secured a last-gasp win over New Zealand in October - they both flew out the blocks with intent, looking to keep the ball in hand at every opportunity and lay down a marker.

The Springboks, aiming to bounce back from a shock opening defeat to Australia, edged the early sparring and took the lead when classy full-back Le Roux weaved through New Zealand's fragmented defence after 10 minutes. Handre Pollard added the conversion and a penalty of his own to make it 10-3 to the hosts after 20 minutes.

The world champions struggled to chip away at the brick-wall Boks' defence, but a breakthrough finally came on the interval as Sopoaga showed superb vision on the run to send Ben Smith in at the corner. The Highlanders fly-half then added the extras to make it all-square at the break.

Any thoughts the high intensity would drop off were dashed as centre Kriel bagged his second try in as many games after 46 minutes for the hosts, but Coles hit back quickly for New Zealand. Pollard and Sopoaga both added the extras to make it 17-17 after 49 minutes.

Pollard nudged the Boks back in front with a penalty before Sam Whitelock was sent to the sin bin on the hour-mark as the All Blacks strained under pressure in their own 22.

The visitors held firm to remain unscathed before Whitelock returned and they took the lead for only the second time in the match in the 74th minute.

After a sustained spell in South African territory, McCaw provided the sucker-punch - catching out the Boks' lineout by dummying it long and then going short to dot down with ease.

Sopoaga added the extras and a late penalty to take his tally to 12 points and secure victory after a truly heavyweight battle.