Having been beaten in Cardiff by the Samoans in 1991 and 1999 it was vital that Warren Gatland's men triumphed in the coach's home town of Hamilton. Had they lost their World Cup campaign might well have been over after two defeats.
But some heroic defence, allied to Williams' try and 12 points from the boots of James Hook and Rhys Priestland, saw them through to a victory that keeps them on course for a possible quarter-final place.
In a tight game, it was a try on the stroke of half-time from Bath-bound prop Anthony Perenise that split the two teams and gave Samoa a deserved 10-6 lead. Wales lost back row man Danny Lydiate with an ankle strain after only 10 minutes and then Hook failed to reappear for the second half because of a shoulder problem.
That meant another 2009 British & Irish Lion, Lee Halfpenny, was pressed into emergency service at full back and it was his run that paved the way for Williams' try. Wales are third in the Pool D table, behind South Africa and Samoa, and have Namibia and Fiji left to play.