Wales went close to losing a game they should have won comfortably before edging home 24-22 against South Africa in Cardiff.

Full-back Leigh Halfpenny's 68th-minute penalty saved the day after the Springboks fought back from 18 points adrift just before half-time to lead in the final quarter.

Two tries by New Zealand-born centre debutant Hadleigh Parkes and a Scott Williams touchdown, plus three Halfpenny conversions, left Wales in total control as the interval approached.

But the Springboks produced an unexpected recovery act, hitting back through tries from wing Warrick Gelant, fly-half Handre Pollard and centre Jesse Kriel, while Pollard added a penalty and two conversions.

It left Wales to reflect on an autumn series that realised losses to Australia and New Zealand, plus an ugly 13-6 victory against unfancied Georgia and a win against South Africa that raised more questions than it delivered answers.

“It's been amazing, a dream come true,” Parkes said afterwards. “I never thought this day would come and I'm just extremely humbled by the opportunity.

“It's a huge privilege and an honour to come out here and play in front of a fantastic stadium and a fantastic crowd. It's a lovely country.

“You dream of these kinds of days, so very happy.”

Even though Wales' list of absentees ran into double figures, South Africa performed only in patches, were there for the taking and looked a pale imitation of previous Springbok sides to visit the Principality Stadium.

Hadleigh Parkes scores his first try on his Wales debut (Getty)

Parkes, who only competed a three-year Wales residency qualification period hours before kick-off, was the shining light as he became the the first Wales player since wing George North seven years ago - also against South Africa - to score twice on debut.

Wales settled impressively and they took a fifth-minute lead when fly-half Dan Biggar's superbly-placed kick was caught at full speed by wing Hallam Amos, who cut inside before a delivering a scoring pass to Williams.

Halfpenny converted, but the home side were not finished, and Biggar struck again with another teasing kick over the top of South Africa's defence that this time Parkes collected for a debut Test try after just eight minutes, before Halfpenny's conversion made it 14-0.

Warrick Gelant dives onto the ball to score just before half-time (Getty)

Wales were a step ahead in thought and deed, and scrum-half Aled Davies led a break-out that had South Africa defenders retreating, yet the Springboks were starting to exert scrummaging authority, targeting home prop Scott Andrews and gaining penalties as a result.

Pollard opened South Africa's account with a penalty nine minutes before half-time, before South Africa proved architects of their own downfall when full-back Andries Coetzee saw an attempted clearance kick charged down by Biggar before number eight Taulupe Faletau gathered and sent Parkes over unopposed for another touchdown.

Halfpenny's conversion took Wales 18 points clear, only for South Africa to keep their slender hopes alive when wing Dillyn Leyds ran from inside his own 22, and a flowing move ended with Kriel kicking into space and Gelant marking his first Test start by winning a race to score.

Handre Pollard dives over the line to score South Africa's second try (Getty)

Pollard added the extras to cut Wales' advantage, yet South Africa still had it all to do, trailing 21-10 at the break.

And the Springboks suffered an immediate setback when injured skipper Eben Etzebeth failed to appear for the second period, increasing an already acute degree of difficulty against opponents eager and willing to run possession.

South Africa, though, suddenly looked up to the task, and a 46th-minute Pollard try gave Wales cause for concern as a healthy advantage continued to be chipped away at, while a double change saw head coach Warren Gatland sent on prop Wyn Jones for Rob Evans and replace Biggar with Rhys Patchell.

Jesse Kriel barges his way over for a try (Getty)

But the Springboks were on a roll, and they went ahead for the first time nine minutes later as Kriel rounded off a crisp move by brushing aside Halfpenny's challenge to claim a try that Pollard converted.

Halfpenny then kicked a penalty 12 minutes from time to put Wales back in front, but it was far from the convincing home win that looked likely at one stage.

Captain Alun Wyn Jones said: “We wanted to finish 2017 off for the fans, it's been an interesting autumn from our point of view.

“We felt we had two good halves against Australia and New Zealand, we needed to cap it off today and I'm proud of the squad and the character we showed.

“We felt we missed a few opportunities again but we finished on a high.

“We're disappointed by the some of the results but we feel positive in the fact we are going forward. We're not going to shy away from the fact we've lost two from four, but we're trying to change things and increase our attacking rugby.”

Teams

Wales: Halfpenny, Amos, S. Williams, Parkes, S. Evans, Biggar, A. Davies, R. Evans, Dacey, Andrews, Hill, A. Jones, Shingler, Navidi, Faletau.

Replacements: Dee, W. Jones, R. Jones, Lydiate, S. Davies, Webb, Patchell, Watkin.

South Africa: Coetzee, Leyds, J. Kriel, Venter, Gelant, Pollard, Cronje, Kitshoff, Marx, W. Louw, Etzebeth, de Jager, Kolisi, du Toit, Du Preez.

Replacements: Am, Schreuder, Mbonambi, Nyakane, T. Mohoje, Cassiem, Dreyer.