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 Australia's Gold Coast.
The lead changed four times in a frenetic last five minutes but the Springboks kept their nerve to deliver Jantjies the opportunity to secure a famous victory from in front of the posts.
"Thank you to the people back home for not giving up on us. We're looking forward to coming home tomorrow," said South Africa skipper Siya Kolisi.
The All Blacks were already assured of the championship title after their victory over the Springboks last weekend, but with Saturday's win the world champions will move back above their great rivals to top 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, they were forced to battle back from a 20-14 half-time deficit to take the lead in the 52nd minute when winger Makazole Mapimpi went over in the corner for the final try of the contest.
Winger Sevu Reece, number eight Ardie Savea and scrumhalf Brad Weber scored tries in the first half for New Zealand but they had to be satisfied with three penalties in the second half that were not enough to maintain their 100% record in 2021.
Jordie Barrett kicked his third 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 in the final seconds.
Frans Steyn boomed the ball into touch and the Springboks lineout did its job before relentless pressure in the middle of the pitch resulted in a penalty call against New Zealand for offside.
The victory snapped a 10-match winning streak for the All Blacks going back to last year and should do much to ease the pressure on the South Africans after they were pilloried for back-to-back losses to Australia.
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 bottom