Robert du Preez went from hero to villain as the Sharks flyhalf gave the Springboks a late lead before his attempted clearance after the restart saw Ryan Alias score the winning try as Wales beat the Springboks 22-20 at the RFK Stadium.
Gareth Anscombe got the game underway in very wet RFK Stadium and the difficult conditions were immediately obvious with both teams struggling to hang onto the ball.
Travis Ismaiel conceded an early penalty which gave Anscombe the chance to have a shot at goal, but the Cardiff Blues pivot pushed his effort wide.
South Africa then managed to get some front foot ball and started to apply the pressure which eventually saw Elton Jantjies put the first points on the board as he calmly slotted a penalty just before the 20th minute.
Wales got gradually better but were dealt a big blow when Steffan Evans was forced to leave the field with a knee injury.
Shortly after, Wales pounced on a turnover ball in the Springboks half as some quick hands and short passes saw Hallam Amos go over for the first try of the match and Anscombe added the additional two points.
A mistake from Ismaiel then saw Wales on the attack again and debutant Tomos Wiliams managed to slip two tackles before crashing over and a good conversion from Anscombe gave the Welsh a 14-3 lead.
Embed from Getty Images
A late five metre lineout gave the Boks a chance to hit back just before half time, but another handling error gave Wales the chance to put the ball into touch and head into the changeroom with a nine-point lead.
The start of the second half saw the return of Curwin Bosch and South Africa were on the attack from the get go. The early pressure eventually forced an error as Ismaiel snatched up a no look pass by Amos pass before diving over the try line with Jantjies nailing the conversion.
Shortly after the restart, Oupa Mohoje was penalised for sealing off the ruck and Anscombe stepped up and split the poles to increase the lead to seven points.
The game began to open up as Ross Moriarty broke the Springbok defensive line and Wales looked like they had the numbers to go all the way, but Wales lost the ball as hey tried to spread it wide.
Springboks then began to ring the changes as a new front row was introduced as well as Gelant back on, this time in place of Makazole Mapimpi.
Owen Watkin received a yellow card in the 56th minute for deliberately knocking the ball out after Jantjies chipped over the Welsh defence with Jesse Kriel challenging the inside centre for the ball.
The resultant penalty saw a good scrum from South Africa and Andre Ezterhuizen broke the line before the ball was spread out wide to Mapimpi who returned to the field just in time to run in his first test try. Jantjies then brilliantly added the extra two points from the touchline to level the scores.
South Africa continued to put the pressure on as Jantjies pinned them back in their 22m and Williams clearance gave the Springboks an attacking lineout. From the lineout, Ezterhuizen took it up well before the Boks again looked wide, this time to Ismaiel who came inches short of the try line.
As the game entered the last 10 minutes, a scrum penalty for the Springboks gave replacement Robert du Preez a chance to open his test points account as he slotted a straightforward effort in front of the poles to give South Africa the lead.
A messy restart then saw a poor clearance from du Preez charged down and Ryan Alias was alert to the situation as he dived onto the ball to score the try and regain the lead for Wales.
The Springboks had a late chance to win the match, but Sikhumbuszo Notshe knocked the ball on as they began their time under Rassie Erasmus with a loss.