Warren Gatland’s side had a poor first half and went to the interval 12-3 down with Springbok fly-half Handre Pollard kicking four penalties to one from Dan Biggar.
But in the second Luke Cowan-Dickie crossed the whitewash and while South Africa responded through Faf de Klerk, it was the Lions who came out on top narrowly.
The boot of Biggar and a late Owen Farrell penalty proved crucial.
The Lions had been forced into a late change with Wales loosehead prop Wyn Jones forced to withdraw due to a shoulder injury. Rory Sutherland came in with Mako Vunipola on the bench.
Biggar put an early up and under into the South African 22, but the Lions were penalised for being in front of the kicker and South Africa released the pressure.
It was immediately obvious how important the kicking and breakdown battle was going to be as both teams were forced into plenty of early work both in the air and on the ground.
Elliot Daly was also smashed by Lukhanyo Am in midfield.
A penalty from Pollard, who led his team out on his 50th South Africa appearance, put the hosts ahead.
He then doubled the Springbok advantage after Tom Curry tackled his Sale team-mate and South African scrum-half De Klerk late.
Biggar made it 6-3 after South Africa were penalised for offside but the Lions had to be thankful to the immense Maro Itoje for some superb breakdown work which stopped a Springbok forward drive.
Pollard then kicked a third and fourth penalty as poor discipline continued to cause the Lions problems.
Gatland’s side also struggled to get going at the line-out.
Biggar surprisingly missed a second penalty attempt and a monster effort from Daly from the halfway line fell just short and De Klerk cleared.
And just before the break Robbie Henshaw made a sublime clean break through midfield but Willie le Roux got back to tackle and the ball went forwards.
South Africa changed their entire front row for the start of the second period bringing on Malcom Marx and props Steven Kitshoff and Frans Malherbe.
But it didn’t stop the Lions from starting with a bang. Biggar kicked to the corner instead of option for three points and a strong line-out drive ended with Cowan-Dickie going over.
It was a big decision from captain Alun Wyn Jones which paid off.
Biggar’s kick got the Lions back into it at 12-10.
Le Roux thought he had responded straight away for South Africa. He raced on to a kick ahead by Am, but South African TMO Marius Jonker decided he was in front of his team-mate.
Jonker was then called into action again and this time he awarded a South African try.
Pieter-Steph du Toit fed Makazole Mapimpi. The flanker tried to collect the ball and although neither he or Mapimpi couldn’t, De Klerk picked up to score.
Jonker decided the ball didn’t go forward off either player and the try was given.
Pollard didn’t convert and Biggar responded with two more penalties to make it 17-16.
South Africa conceded several penalties whenever the Lions retained the ball for long phases.
The Lions introduced Vunipola, Ken Owens and Hamish Watson and in the 63rd minute, South Africa gave away yet another penalty.
Biggar’s best kick of the day from the left-hand touchline put Lions into the lead at 19-17 for the first time. Conor Murray also entered the fray at scrum-half for Ali Price.
But soon after coming on, Watson gave away a penalty for upending Le Roux. Fortunately for the Lions, Pollard missed the kick from distance.
Biggar was then forced off for a head injury assessment. Owen Farrell, who had come on for Daly, moved to fly-half with Daly having to return to the field.
And when the Lions won a big scrum penalty in the 68th minute, you felt like Gatland’s men were on top.
Jonker was then called into action again as he ruled out a South African try for a knock on by Cheslin Kolbe as he competed for a high ball with Liam Williams.
It was yet another crucial moment and when Farrell kicked a 79th minute penalty, it made the game safe for the Lions.
Gatland’s men now lead the Test series 1-0 with two games to play.