Wales 31 South Africa 34:World champions South Africa delivered a classy and ruthless display when it mattered to deny Wales in an epic Millennium Stadium encounter.
The Springboks wiped out an alarming 16-3 deficit to score 28 points in the second and third quarters - but Wales came desperately close to claiming only a second win in 104 years against their illustrious opponents.
Wales matched South Africa 3-3 on tries - centre James Hook, 18-year-old wing Tom Prydie and substitute lock Alun-Wyn Jones touching down - while the Springboks replied with scores for wing Odwa Ndungane, flanker Dewald Potgieter and centre Juan de Jongh.
Outhalf Ruan Pienaar kicked 16 points and fullback Francois Steyn slotted a long-range penalty, with Stephen Jones booting 13 points and Hook dropping a goal for Wales.
Wales though now head off on a demanding two-Test tour of New Zealand knowing they missed an outstanding chance to defeat what was a second-string Springboks side.
But there was nothing second-rate about South Africa, whose enviable strength in depth was showcased in all its glory.
Wales, seeking a first Tri-Nations scalp since beating Australia in November 2008, showed three changes from the RBS 6 Nations clash against Italy 11 weeks ago as head coach Warren Gatland handed starts to wing Leigh Halfpenny, prop Paul James and lock Deiniol Jones.
They were without injured record try-scorer Shane Williams, but Hook started after delaying shoulder surgery by a week.
South Africa, who host Six Nations champions France in Cape Town next Saturday, paraded barely a handful of their established Test team, with three players - wing Gio Aplon, centre De Jongh and flanker Francois Louw - making first international starts.
Jones’ ninth-minute penalty opener gave Wales a deserved lead, then Hook doubled the advantage through a drop-goal from an attacking position partly made possible by Phillips’ crunching tackle on Louw.
Jones and his opposite Pienaar exchanged penalties as Wales preserved a six-point advantage before the home side pounced in opportunist fashion.
Hook, who conceded an interception try when France won at the Millennium Stadium in February, this time capitalised on a gift from his opponents.
Springboks skipper John Smit threw out an ambitious midfield pass but it went straight to Hook and he sprinted over from 40 metres for a try which Jones converted.
Wales, playing with fluency and rhythm while also displaying excellent ball-retention, found themselves 16-3 in front before a second Pienaar penalty reduced South Africa’s deficit.
Wales’ defence came under siege before the Springboks fired possession wide and Ndungane dived under Prydie’s committed challenge to score.
Pienaar sent the touchline conversion attempt wide but ended the scoring in a fast and furious first-half by completing his penalty hat-trick, meaning for all their endeavour and no little skill, Wales led by just two points.
And the Springboks needed less than three minutes of the second period to go ahead for the first time.
Wales struggled to handle the strong running of Louw and lock Danie Rossouw, and Rossouw’s delicious one-handed pass to Potgieter sent him through an inviting gap.
Pienaar added the extras, and although Wales responded through a Jones penalty, it was South Africa that now held a two-point advantage as they targeted an 11th successive victory over their hosts.
Wales then battered away deep inside South Africa’s 22, but the streetwise visitors were able to snaffle possession and hack it upfield, gain a penalty and Steyn did the rest from almost 50 metres.
It was impressively clinical rugby by the Springboks, and an object lesson to Wales in terms of taking opportunities at the highest level.
And things quickly deteriorated from a Welsh perspective when South Africa ended the third quarter by moving past 30 points through an exquisite De Jongh try, converted by Pienaar.
The seven-point blast left Wales with it all to do, and however hard the home side huffed and puffed - Davies was held up over the South African line 11 minutes from time - they hinted at no way back until teenager Prydie touched down.
Another Pienaar penalty looked to make South Africa safe, but Jones then gathered Sam Warburton’s pass for a try which set up a nerve-tingling final four minutes.