The Springboks, featuring 16 members of the victorious 2007 squad in the match-day squad, with 11 in the starting 15, allowed the Welsh to dominate possession and the win was far from guaranteed in a tight match.
Tries from Frans Steyn and Francois Hougaard, along with Morne Steyn kicking two conversions and a penalty, were enough to outdo a Welsh side for whom Toby Faletau scored a sole try and James Hook kicked 11 points.
“It’s going to be a most valuable lesson for us getting out of a pretty sticky situation,” said Springboks skipper John Smit. “There’s a bit of work to do but we are pretty delighted with the way this evening went.”
Bok coach Peter de Villiers added: “They never allowed us to get going. It was a test of character. We came to win the first one and we achieved that goal.”
Welsh captain Sam Warburton said the loss was a big disappointment.
“We were quietly confident all week but just came up short. We played really well but we didn’t quite get that victory.”
Wales coach Warren Gatland said the focus would immediately turn to Samoa.
“There were a massive amount of positives. We have to get back on the horse and think about Samoa next week,” the Kiwi said.
“Good sides take it on the chin and front up.”
The game started in the worst possible manner for Wales, South Africa piling on the pressure before Morne Steyn flung out a pass to Frans, the Bok fullback driving his way over Shane Williams and Hook into the corner for a third-minute try the former converted.
But the Welsh then proceeded to dominate proceedings, centre Jamie Roberts back to his block-busting self in midfield.
But South Africa were happy to soak up the pressure, Schalk Burger and Heinrich Brussouw producing a series of hard-hitting tackles to enforce an iron grip on their rush defence, and Frans Steyn easing things with his booming punts.
Hook got Wales on the scoreboard with a 10th minute penalty but narrowly missed an easier second penalty.
Morne Steyn made no mistake with his first penalty, however, while Hook also banged over his third effort in the 31st minute.
Morne Steyn and Welsh counterpart Rhys Priestland then both went wide with two ambitious drop goal efforts just before half-time as the pressure told after a tiring first 40 minutes.
The second-half started with Wales again dominating possession and the Springboks seemingly happy to step back and defend.
Hook took Wales to within one point of the Springboks with a third successful penalty after Butch James strayed offside in front of his own posts.
And then Wales scored through Tonga-born No 8 Faletau, who crashed over after a neatly slipped pass from Priestland after 53 minutes.
Hook converted to make it 16-10 to the Welsh and the Springboks suddenly looked to be on the rack, missed tackles and handling errors to the fore.
Faletau burst through two tackles and offloaded to Roberts who bullocked his way to the line, only to knock on in the tackle.
But South Africa were not out of it, retaking the lead after replacement wing Hougaard popped up in midfield for a soft try under the posts, converted by Steyn, with 15 minutes to play.
It was not over, however, with Wales having two clear chances to take the lead back and only a second victory in 26 meetings with South Africa.
First Priestland skewed a drop goal from in front of the posts and then Hook went wide with a tricky penalty from wide out.