The Springboks snatched victory with a brilliant solo try to Ricky Januarie four minutes from the end when they were down to 14 men and it was fitting that the feisty halfback should kick the ball into touch in the final act as he was the game's standout player.
He was hugged by his adjacent reserve bench teammates, all fully aware of what they had achieved.
Defeat means the All Blacks' world record run of home victories comes to an end at 30 while the South Africans end a decade of losses in New Zealand. It was also their first win at Carisbrook in eight visits.
A much more hardened Springboks pack shaded the forward battle and they deserved to win after showing vast improvement from last week's 8-19 loss at Wellington.
As with that game, it appeared the deadly goalkicking boot of All Blacks first five-eighth Carter would prove the difference but Januarie's effort gave them a two-try-to-one advantage.
His team trailing 23-28, he darted from a ruck 40m out and chipped past replacement fullback Leon MacDonald, regathered and swan dived over. A calm replacement centre Francois Steyn slotted the conversion to hit the front.
The visitors then defended with resilience, watching one dropped goal attempt from Daniel Carter sail wide and charging down the other.
Carter could hardly be blamed for the defeat, having another controlled display and scoring 23 points via seven from seven goal kicks and a dropped goal.
Both teams tried to play with pace but the match was largely dominated by the whistle of Australian referee Matt Goddard, who was hard on anything that resembled foul play and kept an eagle eye on the breakdown.
The Springboks led 17-15 at halftime but it seemed it may not be enough after playing into the wind.
Human dynamo Schalk Burger was at the forefront of another vigorous forward effort, making countless heavy tackles.
The Springboks lineout operated like clockwork, their scrum was much improved from last week and their better kicking game allowed them to play with more structure.
The All Blacks were left with a very inexperienced tight five after lock Ali Williams left the game with a head injury. He clashed heads with Burger in the 15th minute and played on before succumbing.
Kevin O'Neill replaced him to make his test debut, joining first test-starting lock Anthony Boric.
Carter had the All Blacks 6-0 up inside 10 minutes with two penalties, the first from a marginal head high tackle by Burger, an area in which Goddard was particularly sensitive.
It kick-started a penalty goal duel, with Springboks fullback Montgomery kicking one, Carter one, Montgomery two and Carter one to have the hosts 12-9 up.
Williams' departure seemed to lift the Springboks who scored their first try to recalled right winger JP Pietersen, the perfect way to celebrate his 22nd birthday. It came from a stable 5m scrum which allowed No 8 Joe van Niekerk ample room to put his winger over.
First five-eighth Butch James landed a dropped goal before Carter landed a sideline penalty on the stroke of halftime to reduce the margin to two.
After 15min camped on attack, the All Blacks finally broke through in the second half through reserve No 8 Sione Lauaki, who charged 15m to score with just his second touch.
It came off a break from centre Conrad Smith, who ducked under a James tackle and found halfback Andy Ellis in support.
James narrowed the margin with a penalties either side of a wobbly Carter dropped goal, just the second in his test career, to leave the score at 25-23 with 12min to play.
A decisive moment appeared to come soon afterwards when Victor Matfield was sinbinned for a high tackle on Lauaki, from which Carter landed a penalty.
However, Januarie's brilliant try and conversion by Steyn turned history on its head.