Injury-ravaged Wales put in a gallant performance at Twickenham, but ultimately the boot of Handre Pollard and a late Fourie du Preez score kept the Springboks' dreams of an unprecedented third World Cup triumph alive.
© Getty Images
The first half proved to be a breathless spectacle, and it started in fitting fashion when George North was tackled just yards short of the line within the opening three minutes, before a pass flew over the head of 20-year-old Tyler Morgan with the try line gaping.
Ill-discipline, a problem for Warren Gatland's side against Australia in their final pool game, soon became an issue again as they were penalised twice at the breakdown by referee Wayne Barnes, allowing Pollard to knock over two penalties in quick succession.
Wales stole the ball straight back from kickoff and were able to get on the scoresheet when Dan Biggar kicked an easy penalty, although it could have been more for the designated visitors had Luke Charteris not gifted possession back to South Africa in the build-up.
The Springboks quickly restored their six-point lead when Wales conceded another penalty, but it was Gatland's side who drew first blood in terms of tries. Biggar was the creator with an up-and-under that he collected himself before getting the ball away to Gareth Davies, who went over for his fifth try of the tournament.
Immediately after taking the lead, though, Wales were once again penalised and Pollard proceeded to convert his fourth penalty of the match to restore South Africa's advantage.
© Getty Images
The scoring slowed for the remainder of the half, and it looked as though the Springboks would go in ahead when Biggar's penalty from just inside the South Africa half hit the post.
However, moments later he put a drop-goal over to give his side a one-point lead at the break, and he extended that to four early in the second half.
South Africa began to apply heavy pressure, but some heroic defence, coupled with two missed penalties from the previously perfect Pollard, limited the Springboks to just a drop-goal that reduced the deficit back to one.
The 21-year-old returned to form with a kick just past the hour to put his side back in front, but Wales were immediately awarded a penalty at the other end which Biggar dispatched to continue the see-saw nature of the game.
The Springboks struck a killer blow with just five minutes remaining, however, as Duane Vermeulen's brilliant offload from an attacking scrum enabled captain du Preez to dive over in the corner.
It was just the third try that Wales had conceded in the tournament so far, but it proved to be enough as Heyneke Meyer's side held on for a hardfought victory.