Wales made history by beating the Springboks in South Africa for the first time with a dramatic win in Bloemfontein.
Replacement fly-half Gareth Anscombe kicked a brilliant 79th-minute touchline conversion after Josh Adams scored the game's only try.
South Africa, with 14 changes, had appeared to be coasting to victory with four Handre Pollard penalties.
But there will now be a series decider in Cape Town next Saturday.
South Africa had promised to bury Wales in the series in Bloemfontein, a ground that has been described as a graveyard for opposition sides.
And Wales certainly appeared to be dead and buried as they trailed 12-3, but they battled back heroically and crossed with their only real try-scoring opportunity.
Anscombe, on for the injured Wales captain Dan Biggar, kicked the conversion to complete the turnaround.
It was a disjointed attacking performance from Wayne Pivac's side, but they will not care.
The defensive efforts of Dan Lydiate and, most notably, man-of-the-match Tommy Reffell had allowed the tourists to stay in touch with the Springboks before the late drama carried them to Test victory in South Africa at the 12th attempt.
South Africa head coach Jacques Nienaber had sparked controversy when he announced his team, with 19 alterations in the match-day 23 from the team that triumphed by three points in the first Test.
Wales great Sir Gareth Edwards has been among the critics of South Africa's selection approach, believing it disrespected the tourists.
The Springboks vehemently denied this and insisted this was not a B team, a phrase that had not been used by anybody in the Wales camp.
But only lock Eben Etzebeth remained from the first-Test starting side as he earned his 99th cap.
Two uncapped players, Bulls wing Kurt-Lee Arendse and Stormers number eight Evan Roos, started, while four others came off the replacements bench.
In contrast, Wales made one starting change with wing Alex Cuthbert replacing Adams, who dropped to the replacements' bench.
It was the first international in four years at Bloemfontein since England visited and played in front of a capacity crowd.
Prop Trevor Nyakane promised South Africa would be silent bullies and inflict pain on their opponents, but Wales made the ideal start.
South Africa were penalised from the kick-off and Biggar slotted the three points.
The Springboks responded with a flowing move from Warrick Gelant, almost releasing Arendse to score.
Desperate Welsh defence stopped the try, but illegally, and Pollard levelled the scores.
South Africa hooker Joseph Dewba was penalised for a tackle off the ball only for Biggar to put his long-range effort wide, before Pollard missed a similar effort.
Cuthbert's afternoon was over early as he cut a frustrated figure leaving the field to be replaced by Adams.
Basic errors crept into the Wales game, but their resistance was again evident with Elias and Reffell gaining crucial defensive turnovers as half-time arrived with the scores level 3-3.
Wales changed their scrum-half at the interval with Tomos Williams replacing Hardy, while South Africa introduced front-row duo Malcolm Marx and Vincent Koch.
Pollard slotted over his second penalty to give the hosts the lead and back row Deon Fourie, 35, became the oldest South Africa player to make his debut before Pollard slotted over his third penalty.
Wales captain Biggar was finally forced off with a shoulder injury after having a couple of bouts of treatment, with Anscombe coming on.
The Springboks were overwhelming Wales, who again were punished for indiscipline, but Pollard this time hooked his kick wide.
Wales lock replacement Alun Wyn Jones was shown a yellow card for a second successive game by referee Angus Gardner for a supposedly cynical professional foul.
The Wales players were bemused by the decision and pleaded with the on-field officials to consult with the television match official, but the call stood.
Pollard's fourth penalty took South Africa nine points clear before Dillon Lewis added to Wales' tight-head prop injury list as he came off with an arm injury to join Tomas Francis, Samson Lee and Leon Brown on the sidelines.
This allowed Saracens prop Sam Wainwright to make his international debut as Anscombe slotted over a penalty to move Wales within a score, before missing another kick.
Replacement hooker Dewi Lake had been struggling to find his jumpers at the line-out, which stopped Wales building pressure.
After Test rookie Wainwright had helped gain a vital scrum penalty, Wales finally gained possession from a crucial attacking line-out, which eventually allowed Adams to cross in the left corner.
Up stepped Anscombe to slot over the match-winning conversion and this time Wales held to write a new chapter in their history on a day on which Ireland won in New Zealand and England beat Australia in Brisbane.
South Africa: Gelant; Arendse, Kriel, Esterhuizen, Fassi; Pollard (capt) Henrikse; T du Toit, Dweba, Nyakane, Etzebeth, Orie, Coetzee, P-Steph du Toit, Roos,
Replacements: Marx, Mchunu, Koch, Nortje, Elstadt, Fourie, Williams, Willemse.
Wales: LWilliams; Rees-Zammit, North, Tompkins, Cuthbert; Biggar (capt), Hardy; G Thomas, Elias, Lewis, Rowlands, Lydiate, Reffell, Faletau.
Replacements: Lake, Wyn Jones, Wainwright, Alun Wyn Jones, Navidi, T Williams, Anscombe, Adams.
Match officials
Referee: Angus Gardner (Australia)
Assistant referees: Matthew Carley (England), Andrea Piardi (Italy)
TMO: Brett Cronan (Australia).