Wales 19 South Africa 23
South Africa captain Fourie du Preez broke Welsh hearts with a 75th minute try to give the Springboks a 23-19 victory and book their place in the World Cup semi-finals.
Gareth Davies’ first-half try looked to have set Wales on course for only their third victory in 31 Tests over South Africa, but du Preez’s late drama sealed a pulsating win at Twickenham.
Welsh fly-half Dan Biggar kicked 14 points while South Africa’s Handre Pollard kicked 18 and the Springboks go through to meet either New Zealand or France in the last four.
Wales had to beat South Africa for only the third time in their history to reach the World Cup semi-finals.
Warren Gatland’s side won 12-6 in the most recent meeting in Cardiff last year but that victory was just their second against the Springboks in 30 Tests dating back to 1906.
South Africa have made an impressive recovery since their shock opening defeat to Japan and they welcomed back winger JP Pietersen for the clash at Twickenham.
Welsh trio Dan Lydiate, Tyler Morgan, Gethin Jenkins returned to the starting line-up after missing the pool defeat to Australia.
Morgan, making only his third international appearance, showed few signs of nerves early on as the 20-year-old won a brilliant turnover and Wales spread the ball left to George North, who sprinted 20 yards before being brought down just short of the line.
Wales swiftly switched their attack to the right and had a man over, but Jenkins’ looping pass was too just high for Morgan to reach.
South Africa should have been behind, but instead they took the lead as Wales’ impatience at the breakdown allowed fly-half Handre Pollard to kick the Springboks 6-0 in front.
Dan Biggar and Pollard exchanged two more quick penalties before Biggar produced a moment of magic in the 17th minute to give Wales the opening try.
Booting the ball high into the air, Biggar beat South Africa full-back Willie le Roux to the high catch and then instantly released Gareth Davies to dive over for his fourth try of the tournament.
Biggar converted to put Wales ahead, but a fourth Pollard penalty restored South Africa’s lead at 12-10.
Wales continued to threaten in midfield where North enjoyed another bursting run and while Biggar struck the post with a long-range penalty, he swiftly made amends with a drop-goal to put his side 13-12 up at the interval.
More Welsh indiscipline up front, this time from Luke Charteris, who entered a ruck from the side, gave Pollard an early shot at the posts but this time the number 10 failed to take advantage.
Biggar was more precise in the 47th minute, slotting home a penalty for a four-point lead, but South Africa cranked up the heat on the Welsh defence with only an excellent steal from Sam Warburton relieving the pressure.
The Springboks came back again, however, and a Pollard drop-goal ensured their dominant spell did not go unrewarded, although the fly-half shanked another penalty wide shortly after.
As the game drifted towards the hour-mark, South Africa remained in the ascendancy and a superb off-load from Schalk Burger fed Le Roux for a weaving run but Bryan Habana was crowded out in the corner.
After two misses, Pollard recovered his nerve from the tee but the South African lead was short-lived as Biggar returned the favour to put Wales 19-18 ahead with 17 minutes remaining.
Just as the storm looked to have been weathered, South Africa struck with five minutes left as Duane Vermeulen delivered a brilliant backhand pass which released Fourie du Preez to dive into the corner for his 16th international try.
Wales rallied in the final moments but they had nothing left to give and South Africa held on for a thrilling win.