But the departing heroes’ thunder was stolen by teenage Test debutant Harry Robinson, who proved the shining light of an inconsistent Wales display, scoring a blistering try after just 10 minutes that had Shane Williams’ renowned finishing prowess stamped all over it.
Wales, though, struggled to build on the 19-year-old wing’s dazzling effort and they only prevailed courtesy of centre James Hook’s 20-point haul from a try, three penalties and three conversions, plus Aled Brew’s late effort.
Half-backs Stephen Donald (two) and Richie Rees touched down for the Barbarians, with Bath number 10 Donald slotting all three conversions.
Even though the game did not grip a bumper crowd of 57,000, they still had chance to bid wing Williams and flanker Williams farewell.
The pair – who boast 187 caps between them – had few chances to shine on their final Test outings as Shane retired in Baa-baas colours and Martyn went on early in the second period for his 100th Wales appearance before ending the game as Wales captain.
It was an emotional and nostalgic farewell for both players, but Wales must look at the bigger picture, and a scrappy showing was not what they wanted just seven days before tackling Australia in Brisbane.
An advance party of 16 players, featuring most of their Test regulars, are already Down Under preparing with assistant coach Shaun Edwards, but a further 18 players involved today will join them early next week.
Robinson, full-back Liam Williams and prop Rhodri Jones all made their Wales bows, yet caretaker coach Rob Howley was left with more questions than answers as he ponders his final tour squad make-up.
Williams led the Baa-baas out to a standing ovation, but he immediately found himself in defensive mode as Wales went through several attacking phases that ended with Hook booting a penalty.
It was a promising start by the reigning RBS 6 Nations champions, and they extended their lead after 10 minutes when flanker Justin Tipuric snaffled turnover ball and Robinson sprinted over from 60 metres.
Hook slotted the touchline conversion, and a 10-point lead was deserved reward for Wales’ admirable sense of adventure as they looked to maintain a high tempo.
A second Hook penalty extended the advantage to 13 points, but the Barbarians replied just when it looked as if things were getting away from them.
Shane Williams was used cleverly as a decoy runner, and a slick move ended with lock Mick O’Driscoll sending Donald across for a try that the New Zealand World Cup winner converted.
The score gave Donald and company confidence to start attacking Wales, and the home side briefly lost their way after referee Alain Rolland sin-binned prop Rhys Gill.
It was Irish official Rolland’s first Millennium Stadium appearance since he sent off Wales skipper Sam Warburton during the World Cup semi-final defeat against France in Auckland last October, and once again he did not endear himself to Welsh supporters.
The Baa-baas almost scored immediately following Gill’s departure, but television match official Nigel Whitehouse ruled against number eight John Beattie, and then flanker Mamuka Gorgodze also went close.
Wales found themselves under sustained pressure after Gill departed, and they conceded a second try three minutes before half-time when Rees reacted quicker than his opposite number Lloyd Williams.
Donald again added the extras, and Wales trooped off 14-13 adrift, wondering how a comfortable lead could have evaporated so quickly.
Martyn Williams arrived to a rapturous reception six minutes into the second period as he became the third Welsh cap centurion after Gareth Thomas and Stephen Jones.
And Wales regained the advantage soon afterwards when Hook completed his penalty hat-trick before further reinforcements arrived in scrum-half Rhys Webb and flanker Aaron Shingler.
There was no obvious pattern to the game, and its disjointed appearance suited the Barbarians as Wales lacked much of their early structure and cohesion.
Donald scored his second try midway through the half, and Wales knew they needed to rouse themselves or face the prospect of a second successive defeat against their invitational opponents.
But Hook and Brew then came up trumps during the closing minutes as World Cup semi-finalists and reigning European champions Wales made it six wins from six in 2012.