South Africa survived a massive scare and left it until late to beat Wales 31-30 in Nelspruit on Saturday thanks to a penalty try two minutes from full time.
Match referee Steve Walsh awarded South Africa a penalty try in the 79th minute after Liam Williams was judged to have shoulder charged Cornal Hendricks into touch.
Wales could still have won the match as Dan Biggar had two late drop goal attempts but missed as he was too far out.
The victory is South Africa's 16th consecutive win over Wales who have only beaten the Springboks once and drawn once in the 28 matches between the teams.
Wales, who are playing without a number of their first choice players, lost last week 38-16 in Durban but almost ended a run of defeats that dates back to 1999 as the Springboks had to come from behind to get out of jail.
Ten minutes from full time Wales had a 13 point lead but fullback Willie le Roux slipped through Wales' defence to score a crucial try which brought the Springboks to within six points after the conversion.
As Wales hung on in defence South Africa went for the corner and having shrugged off the first tackler Hendricks was taken out by Williams. Referee Walsh referred the decision to the TMO who ruled that the tackle was illegal and he awarded the penalty try under the posts.
The conversion put South Africa one point ahead for the first time in the match and with a minute remaining. Wales kept the ball alive through almost 20 phases after the siren but the match ended when Biggar's second drop goal went low and short.
Earlier Wales had raced out to a 17-0 lead before South Africa pulled themselves into the game to trail 17-14 at half time.
Wales then opened up a thirteen point gap and with fourteen minutes to play they looked on track to win their first ever match against the Springboks on South African soil.
With lock Flip van der Merwe in the sin bin for an illegal tackle South Africa looked destined for an embarrassing defeat.
But then fullback Le Roux sparked South Africa's comeback with his try which lifted the Springboks and with their heads up Hendricks went for the corner and the decisive penalty try was awarded.
Next week South Africa host Scotland in Port Elizabeth.
Final Score South Africa 31 (14) Wales 30 (17)
Tries - Penalty 2, Hendricks, Le Roux
Con - Steyn (3)
Tries - Roberts, Cuthbert, Owen
Pen - Biggar (3)
Con - Biggar (3)
Referee : Steve Walsh (Aus)
South Africa: 15 Willie le Roux, 14 Cornal Hendricks, 13 JP Pietersen, 12 Jan Serfontein, 11 Bryan Habana, 10 Morné Steyn, 9 Fourie du Preez, 8 Duane Vermeulen, 7 Willem Alberts, 6 Francois Louw, 5 Victor Matfield (c), 4 Flip van der Merwe, 3 Jannie du Plessis, 2 Bismarck du Plessis, 1 Tendai Mtawarira.
Replacements: 16 Schalk Brits, 17 Gurthro Steenkamp, 18 Coenie Oosthuizen, 19 Lood de Jager, 20 Schalk Burger, 21 Ruan Pienaar, 22 Wynand Olivier, 23 Lwazi Mvovo.
Wales: 15 Liam Williams, 14 Alex Cuthbert, 13 Jonathan Davies, 12 Jamie Roberts, 11 George North, 10 Dan Biggar, 9 Mike Phillips, 8 Taulupe Faletau, 7 Josh Turnbull, 6 Dan Lydiate, 5 Alun Wyn Jones (c), 4 Luke Charteris, 3 Samson Lee, 2 Ken Owens, 1 Gethin Jenkins.
Replacements: 16 Matthew Rees, 17 Paul James, 18 Aaron Jarvis, 19 Jake Ball, 20 Dan Baker, 21 Gareth Davies, 22 James Hook, 23 Matthew Morgan