WATCH - Sam Davies the hero as last-gasp drop saves Wales' blushes against brave Japan
Sam Davies got Wales out of jail with a last-gasp drop goal as Japan were thwarted 33-30 at the Principality Stadium.
The Ospreys fly-half, who went on as a second-half substitute, struck during the closing seconds to give Wales victory.
Dan Lydiate, Jamie Roberts and Sam Warburton scored tries, while wing Leigh Halfpenny kicked 15 points as Wales triumphed, yet it was a performance that lacked consistency and finesse - and almost produced a colossal upset.
Japan looked a far more threatening outfit with ball in hand as wings Akihito Yamada and Kenki Fukuoka. plus substitute Amanaki Lotoahea, claimed touchdowns, with fly-half Yu Tamura adding three penalties and two conversions and centre Timothy Lafaele converting Yamada's try.
Wales boss Rob Howley made 10 changes following last weekend's hard-fought win against Argentina, throwing down a selection gauntlet ahead of next week's autumn finale against struggling South Africa.
But few players stood up and were counted as Wales did just enough to make it nine wins from 10 against Japan.
Wales were eager to continue momentum established by a 24-20 victory over Argentina seven days ago, but they had to play second fiddle from kick-off.
Tamura kicked two penalties as Japan led 6-0, with his second successful shot at goal coming after Wales full-back Liam Williams was rightly sin-binned for obstruction on Yamada.
It amounted to a poor start by Wales, but they responded in the 11th minute after possession was rapidly moved wide and Lydiate touched down for his first try in Wales colours, with Halfpenny adding the conversion.
Japan's initial promise quickly evaporated as Wales looked to turn the screw up front, and there was little the visitors could do to halt a vibrant home attack.
Inevitably, they ran out of defensive numbers, and centre Jonathan Davies' half-break proved sufficient as his midfield partner Roberts - back on Wales duty after being dropped for the Argentina game - effortlessly finished off.
Halfpenny's conversion made it 14-6, but Japan hit back strongly before the break, even if Wales gifted them a try.
Fly-half Gareth Anscombe shipped possession on in midfield, but it failed to find a colleague and Yamada gathered a bouncing ball to claim his 14th try in 17 Tests, with centre Lafaele's conversion making it 14-13 at the break.
Halfpenny extended Wales' lead through an early second-half penalty, yet the game continued to lack any real spark, while there was no obvious indication that Howley planned any immediate replacements.
Wales though, moved further ahead after 52 minutes when lock Alun Wyn Jones sprinted into space from a lineout and found Warburton on his right shoulder, with the Wales skipper finishing in style before Halfpenny's conversion made it 24-13.
But Japan hit back immediately through a brilliant touchdown that owed everything to slick passing and rapid handling, with Fukuoka applying a stunning finish in limited space.
Tamura kicked the conversion, and Wales could not relax, having seen their advantage trimmed back to four points.
Another Halfpenny penalty took Wales seven points clear, yet Japan immediately reclaimed field position and they gained a penalty that Tamura landed.
The game was now nip and tuck, as another Halfpenny penalty made it 30-23, but Japan were not to be denied as Lotoahea touched down six minutes from time and Tamura brilliantly converted to make it all square.
Wales pushed as the clock ticked down, and wing Alex Cuthbert knocked on with the line at his mercy, before Davies, who was winning only his second cap, came up trumps amid a frantic finale.