Captain Fourie du Preez's try five minutes from time hauled the Springboks past Wales 23-19 in a thrilling World Cup quarter-final at Twickenham on Saturday.
Wales led 19-18 when scrum-half du Preez, cajoled out of Test retirement by coach Heyneke Meyer, burst down the blindside off a back of a close-range scrum after a superb pass from No 8 Duane Vermeulen.
Fly-half Handre Pollard scored all of two-time world champions South Africa's other points in the classic battle.
"It was a tough game, they came hard at us," Du Preez said after.
"We just said to ourselves 'keep pushing, keep pushing'. At one stage I saw some of the guys lying down and I told the guys 'look we have to go and fight now' and the guys produced."
Du Preez's score gave South Africa a four-point lead and that meant Wales, with goal-kicking fly-half Dan Biggar off the field for a head injury assessment, needed a try to regain the lead in a brutal and see-saw contest.
Biggar had a fine match, kicking 14 points and setting up Gareth Davies for Wales' only try.
Wales had won just two of their previous 30 Tests against South Africa, a run including 16 straight defeats.
But they did come out 12-6 on top when the teams last met in Cardiff 11 months ago.
South Africa, who suffered a shock 34-32 loss to Japan in their first match of this World Cup, recalled JP Pietersen after the wing missed the 64-0 rout of the United States with a knee injury.
Wales brought back tough-tackling flanker Dan Lydiate following their 15-6 pool loss to Australia. Veteran prop Gethin Jenkins returned to the front row.
Meanwhile 20-year-old Tyler Morgan, winning just his third cap, partnered Jamie Roberts in midfield as the injury-hit Welsh were again forced into a backline reshuffle after Liam Williams was forced out of the tournament.
Wales failed to score a try against Australia and, having been blasted by coach Warren Gatland for failing to take their chances, they missed an early opportunity on Saturday.
George North powered his way down the left wing only to be tackled short of the line.
The ball was worked across field but, with Morgan in space, Jenkins' pass sailed over the centre's head and into touch.
Instead, South Africa took the lead through Pollard's eighth-minute penalty as English referee Wayne Barnes penalised Wales for not rolling away at the breakdown.
Pollard made it 6-0 minutes later.
Wales, with Roberts and lock Alun Wyn Jones charging hard, won a penalty in front of the posts and Biggar made no mistake.
Pollard restored South Africa's six-point advantage soon after.
Wales hit back with a fine try in the 18th minute.
Biggar regathered his own high kick, beating South Africa full-back Willie le Roux to the ball, and then released Davies for a try which Biggar converted to make it 10-9 to Wales.
It was short-lived, however, with Pollard's fourth penalty putting the Springboks 12-10 ahead.
Vermeulen and Francois Louw, with Schalk Burger in support, got through an immense amount of ruck work in a gruelling contest for possession against Wales loose forwads Taulupe Faletau, skipper Sam Warburton and Lydiate
But when the Springboks came in from the side a minute before half time, they conceded a penalty only for Biggar's 48-metre kick to hit the right post.
Biggar, however, was on target with a drop-goal in the final play of the first half to edge Wales into a 13-12 lead at the brek.
Early in the second half, 2011 semi-finalists Wales were penalised for pulling down a maul only for Pollard to miss his first goal-kick of the match.
Burger conceded a 46th-minute penalty for obstruction and Biggar's long-range effort from near the half-way line sailed over to make it 16-12 to Wales.
Pollard's drop-goal cut a tiring Wales' lead to 16-15 before he missed a 41-metre penalty.
South Africa won another penalty heading into the final quarter and Pollard from out wide on the left, nudged the Springboks into an 18-16 lead.
From the re-start, however, South Africa were off their feet at a ruck and Biggar edged Wales ahead at 19-18 until Du Preez struck.
Date created : 2015-10-17