A converted late penalty try secured a last-gasp 31-30 victory for South Africa against Wales in Nelspruit on Saturday, killing Welsh hopes of an historic rugby win.

Wales led for most of the match, but two yellow cards late in the first half and a South African onslaught late in the second that culminated in a penalty try, proved too much for the visitors.

Welsh coach Warren Gatland described the loss as "probably the worst" experience of his coaching career.

"I'm pretty gutted about it. I'm proud of the performance, the turnaround and how the guys fronted up ... but you play one of the top teams in the world and they keep going for 80 minutes."

He refused to blame the loss on a series of unfavourable refereeing decisions that led to two penalty tries and two yellow cards against the visitors.

South Africa captain Victor Matfield, who became the most capped Springbok in his 112th Test, praised his side as having the mark of world champions.

"It's just great how calm the guys stayed and the character they showed," Matfield said.

"I really believe if you want to win a World Cup you have to have character... and the guys showed it today, even until the last second."

With conditions perfect, both teams sought to pass the ball around in the opening stages, probing and prodding for openings.

Dan Biggar opened the scoring when the Springboks were pinged at the ruck, slotting home a penalty, and, after Morne Steyn had missed a chance to bag three points for his side, Wales got the first try of the game.

Alex Cuthbert collected a crash ball, broke through the 'Boks's back line, offloading to Jamie Roberts who powered in to touch down under the posts.

With Welsh tails up and the 'Boks in disarray, Cuthbert crossed the line himself just moments later, with Biggar again converting to make it 17-0.

But then the wheels came off.

Close to the half-hour mark they were reduced to 14 men, with Luke Charteris yellow-carded while rucking out on his own try line.

The Springboks were awarded a penalty try moments later and the visitors were reduced to 13 men with Biggar joining Charteris in the sin bin.

South Africa took further advantage with a fluid, ranging, length-of-the-field try that was eventually run home by Cornal Hendricks, his first try for his country.

That left South Africa trailing 14-17 at half-time.

Wales managed to weather the first minutes of the half and, when back to 15 men, looked a different proposition.

After putting the ball through pressure phases in the 'Boks's 22, Ken Owens opened the second half scoring with a drive over the line and Biggar converted making it South Africa 14 Wales 24.

On 55 minutes, Steyn briefly cut the deficit by three points with a successful penalty, only to be matched seconds later by Biggar's own effort, which brought the score to 17-27.

It was then the Springboks' turn to be reduced to 14 men, when Flip van der Merwe was sin-binned for taking out Wyn Jones in the air.

Another penalty for Biggar on 65 minutes increased Wales's lead to 13 points.

With eight minutes to go, a try from in-form 'Boks full back Willie le Roux and Steyn's conversion put South Africa back within striking distance.

Then in the dying moments, Hendricks was ploughed into touch in a move that referee Steve Walsh judged to be a shoulder charge.

After consulting the TMO he awarded a penalty try which was converted by Steyn to give the 'Boks a one-point advantage.