South Africa advanced to the 2015 Rugby World Cup semi-finals thanks to a 23-19 victory over Wales in an intense battle at Twickenham on Saturday.
Springbok skipper Fourie du Preez scored in the 75th minute to snatch victory in an epic game that could have gone either way.
South Africa will now face the winners of Saturday's other quarter-final between France and defending champions New Zealand next weekend at the same venue.
You could not have asked for the greater physical battle in a match played at a furious pace. It was simply thrilling as the lead constantly swapped hands.
A monumental effort from the South African pack was at the heart of this victory as their big ball carriers worked tirelessly, relentlessly hammering away at the gainline.
There was precious little to separate the sides at the interval as Wales led 13-12 thanks to a try from scrum-half Gareth Davies and a drop-goal on the stroke of half-time from Dan Biggar.
The battle of the breakdown had been billed as the decisive area by both camps before kick-off and the ruck penalty count against Wales proved significant, meaning that South Africa led for most of the opening 40 minutes.
It was a tale of missed chances early on and Wales had a great opportunity to score after Tyler Morgan ripped the ball off Damian de Allende, setting up George North to charge up field, but Gethin Jenkins threw a shocker of a pass when Morgan had acres of space on the overlap after the ball was recycled.
Three consecutive ruck penalties allowed Handre Pollard to give South Africa a 6-0 lead although Biggar pulled three points back when South Africa were pinned down in front of their own posts.
But Wales were being hammered by referee Wayne Barnes at the breakdown and Pollard made it 9-3 just after the 15 minute mark.
Wales hit back with the first try of the game as Biggar collected his own bomb before offloading to Davies, who ghosted over. Biggar added the conversion to give Wales the lead for the first time.
The Springboks edged back in front at the end of the first quarter as Pollard slotted his fourth penalty, this time for obstruction.
A tense territorial battle ensued as bombs rained down in both directions with the Boks just holding the upper hand in terms of possession, but twice Du Preez's cross-field kicks just missed the chasing JP Pietersen.
Biggar hit the post with a long-range shot but with time up, he sent a drop-goal straight through the middle to give Wales the narrowest of advantages as the teams headed for the changing rooms.
Pollard sent a penalty wide early in the second-half after Wales were pinged for pulling down a maul but Biggar hit the target from over 40 metres out after Schalk Burger went offside.
The Springbok pack turned up the heat with a prolonged period of massive ball carrying but the Welsh defence brilliantly held firm. The men in green eventually turned to Pollard to slot a drop of his own, to make it a one-point ball game once again.
The Springbok fly-half should have given his team the lead but missed the mark for the second time. A scything run from Willie le Roux gave Bryan Habana a glimpse of the line and the World Cup try-scoring record only to be stopped just short, meaning Wales hit the hour mark 16-15 up.
The Boks wrestled the lead back as Jesse Kriel forced Gareth Anscombe to hang on and Pollard landed his sixth penalty but Eben Etzebeth was penalised on the deck immediately after the restart and Biggar duly restored the Welsh advantage, setting up a nail-biting finale.
With 'Bread of Heaven' resounding around Twickenham Wales were in sight of their second consecutive RWC semi-final but a big scrum set up Duane Vermeulen to break off the back with his offload sending Du Preez over in the corner.
Pollard missed the conversion, leaving Wales within touching distance but the Boks held on.
Man of the match: Du Preez obviously deserves a mention and Vermeulen was instrumental but Schalk Burger was phenomenal, making 26 carries in a vintage performance.
Moment of the match: There can be only one; Vermeulen's offload to set up the winning try in the dying minutes was sublime.
Villain of the match: No nasty stuff to report.
For South Africa:
Try: Du Preez
Pens: Pollard 5
Pens: Biggar 3
South Africa: 15 Willie le Roux, 14 JP Pietersen, 13 Jesse Kriel, 12 Damian de Allende, 11 Bryan Habana, 10 Handre Pollard, 9 Fourie du Preez (c), 8 Duane Vermeulen, 7 Schalk Burger, 6 Francois Louw, 5 Lood de Jager, 4 Eben Etzebeth, 3 Frans Malherbe, 2 Bismarck du Plessis, 1 Tendai Mtawarira.
Replacements: 16 Adriaan Strauss, 17 Trevor Nyakane, 18 Jannie du Plessis, 19 Pieter-Steph du Toit, 20 Willem Alberts, 21 Ruan Pienaar, 22 Pat Lambie, 23 Jan Serfontein.
Wales: 15 Gareth Anscombe, 14 Alex Cuthbert, 13 Tyler Morgan, 12 Jamie Roberts, 11 George North, 10 Dan Biggar, 9 Gareth Davies, 8 Taulupe Faletau, 7 Sam Warburton (c), 6 Dan Lydiate, 5 Alun Wyn Jones, 4 Luke Charteris, 3 Samson Lee, 2 Scott Baldwin, 1 Gethin Jenkins.
Replacements: 16 Ken Owens, 17 Paul James, 18 Tom Francis, 19 Bradley Davies 20 Justin Tipuric, 21 Lloyd Williams, 22 Rhys Priestland, 23 James Hook
Venue: Twickenham Stadium, London
Referee: Wayne Barnes (England)
Assistant Referees: JP Doyle (England), George Clancy (Ireland)
TMO: Graham Hughes (England)
By Ross Hastie at Twickenham