Wales' first World Cup appearance in coach Warren Gatland's home town almost became a horror show before Shane Williams delivered the happy ending that provided a 17-10 win over Samoa and kept alive their quarter-final hopes.
Samoa, World Cup conquerors of Wales in 1991 and 1999, threatened a hat-trick until Williams poached his 55th Test try 13 minutes from time.
It got Wales out of jail and means they are likely to progress from Pool D if they win their remaining fixtures against Namibia and Fiji.
But Wales' performance was far from the standard they hit in pushing world champions South Africa to the brink of defeat last weekend, albeit hindered by injuries to full-back James Hook (shoulder) and flanker Dan Lydiate (ankle).
Hook kicked two penalties before he departed at half-time, while fly-half Rhys Priestland also found his range twice to thwart a Samoan side that created more clear-cut attacking opportunities.
Bath-bound prop Anthony Perenise crossed for the South Sea Islanders just before half-time, with full-back Paul Williams adding a conversion and penalty, but Wales did just enough.
And the win keeps them on course for a potential last-eight clash against Ireland in Wellington on October 8.
Wing Williams, Wales' record international try-scorer, finished off a 70-metre move sparked by the invention and creativity of Hook's replacement Leigh Halfpenny.
And the score gave Wales critical breathing space when Samoa pushed relentlessly during the closing minutes, securing a win that will not live long in the memory.