Elton Jantjies kicked a penalty after the final hooter as South Africa snapped a three-match losing streak in dramatic fashion with a 31-29 win over New Zealand in a thrilling final match of the Rugby Championship on Saturday.
The lead changed four times in a frenetic last five minutes on Australia's Gold Coast but the world champions kept their nerve to deliver Jantjies the opportunity to secure a famous victory from in front of the posts.
The All Blacks were already assured of the championship title after their victory over the Springboks last weekend, but Saturday's win will send South Africa back above their great rivals to the top of the world rankings.
The victory was a reward for the Springboks showing much more adventure but just as much grit and physicality as they had in their previous three matches in Australia.
After starting well with an early try from Damian de Allende, they were forced to battle back from a 20-14 halftime deficit to take the lead in the 52nd minute when winger Makazole Mapimpi went over in the corner for the final try of the game.
The victory should do much to ease the pressure on the Springboks after they were pilloried for the manner of back-to-back losses to Australia and last week's defeat in Townsville.
"It was unbelievable," said South Africa coach Jacques Nienaber.
"It's been a tough four weeks but in fairness, that's the margins when numbers one, two and three in the world play against each other.
"I don't think we're there yet, but I think we were a little bit better today."
Winger Sevu Reece, number eight Ardie Savea and scrumhalf Brad Weber scored tries in the first half for the All Blacks but three penalties in the second half were not enough to maintain New Zealand's 100% record in 2021.
"We're obviously bitterly disappointed to lose any game at the end when you've got control of it," said coach Ian Foster.
"It's frustrating but I thought the South Africans played superb. They came with a lot of attitude, they carried hard, they moved us around and challenged us in many ways."
Jordie Barrett kicked his third penalty four minutes from time to give the All Blacks a 26-25 lead but Jantjies immediately responded with a long-range drop goal to edge the Springboks back in front.
Another towering effort from the All Blacks fullback looked to have won the match with a minute remaining, especially when the South Africa kickoff failed to go 10 metres.
But the Springboks would not be denied and number eight Duane Vermeulen came up with a crucial turnover that drew a penalty in the final seconds.
Frans Steyn boomed the ball into touch and the Springboks lineout did its job before relentless pressure on the 22 metre line resulted in a penalty call against New Zealand for offside, which allowed Jantjies his match-winning moment.
The loss snapped a 10-match winning streak for the All Blacks going back to last year but Foster said overall he had been pleased with his team.
"It shows we've still got a bit to learn but (I'm) intensely proud of a campaign in which I think we've taken a great step forward," he added.
The Wallabies will finish second in the championship after an earlier 32-17 win over Argentina at the same Robina Stadium with South Africa third and the winless Pumas last.