Shane Williams scored a vital second-half try to ensure Wales overcame Samoa's stern challenge in Hamilton to boost their hopes of making the World Cup quarter-finals.
Samoa led 10-6 at the break through an Anthony Perenise try and Paul Williams' conversion and penalty.
James Hook kicked two first-half penalties for Wales and Rhys Priestland a brace after the break.
Wales wing Williams sealed victory 15 minutes from the end.
It was Wales' first World Cup win over the islanders in three attempts, having lost to them in Cardiff at the 1991 and 1999 tournaments and left Samoa needing to beat Fiji and reigning champions South Africa in their remaining games if they are to progress.
Both sides showed signs of nerves early on with passes not going to hand and kicks going out on the full.
Wales' edginess manifested itself in the sort of penalty offences they avoided in their opening defeat by South Africa.
For Samoa, poor passing was a blight, particularly when Daniel Leo sent what should have been a scoring effort beyond the reach of Sailosi Tagicakibau into touch.
But the islanders had also seen fly-half Tasea Lavea - a late pre-match replacement for Tusi Pisi - send the kick-off into touch on the full, then conceded a penalty at the first scrum.
However, Hook's penalty shot from halfway fell short and in the fourth minute Leo blew Samoa's first chance.
Wales seemed to have the edge in the scrums, but their lack of control of possession and Samoa's alertness to the opportunities cost Warren Gatland's side several attacking platforms in the opening period.
The men in red's line-out was also shaky as they switched from the safety-first options taken against the Springboks to a bolder approach.
When flanker Dan Lydiate departed to be replaced by Andy Powell after only seven minutes, Wales gained a ball-carrier, but lost a grafting ball-winner.
Flanker Maurie Fa'asavula's high tackle on Priestland allowed Hook to open the scoring after 11 minutes, but Paul Williams levelled after Mike Phillips was penalised for obstruction.
Wales' best attacking moments of the opening period came when Jamie Roberts' midfield power became evident.
Scrum-half Phillips was also a catalyst, combining with prop Adam Jones to set up a Priestland drop-goal attempt that drifted wide.
Samoa's indiscretion at a scrum allowed Hook to put Wales back into the lead and Williams failed with an attempted reply.
Fa'asavalu was penalised for a double movement as he tried to finish off a sustained attack.
But after Wales were again penalised at a ruck for diving on in midfield, Samoa built more momentum.
And despite some outstanding defence, Samoa were not to be denied the opening try. Having completed almost 20 attacking phases Bath-bound prop Anthony Perenise cut back against the defence to go over.
Paul Williams added the conversion to the late first-half score and Samoa deservedly led 10-6 at the break.
Wales suffered a further blow at half-time, losing Hook who was replaced by Leigh Halfpenny at full-back.
Priestland took over the goal-kicking duties two minutes after the break, seeing his first attempt bouncing over via the crossbar.
But without Lydiate to do his work, hooker Huw Bennett was penalised for holding on at the tackle, this time in Samoa's 22.
Wales' breakdown troubles continued to draw Irish referee Alain Rolland's wrath, but another Williams penalty attempt drifted wide.
Rolland was equally diligent at the line-outs where Samoa's delaying tactics earned his attention, but Wales let them off when Adam Jones was penalised at the scrum that followed.
Having stripped AlesanaTuilagi of the ball Wales launched a patient attack in which Roberts was prominent out wide.
The move paid dividends when Fa'asavula and Mahonri Schwalger went over the top at a ruck, allowing Priestland the chance to put his side into the lead with 16 minutes remaining.
Having entered the fray as replacement, Halfpenny seized a chance to break out of defence after gathering a high kick.
He had support from Jonathan Davies and although the centre's final pass was poor, wing Williams was on hand to gather and score to put Wales 17-10 ahead after 68 minutes.
Back came Samoa and when presented with a kickable penalty opportunity in Wales' 22, Samoa opted for the line-out as they sought a try and conversion.
But Toby Faletau stole possession as Samoa piled on the pressure on Wales' line for Priestland to gather.
At the scrum that followed, Samoa were pulled up for driving early and Priestland cleared from the free-kick.
The Wales fly-half also drew the contest to a close, kicking the ball off the park after Samoa's final attack was thwarted.
Wales: James Hook (Perpignan); George North (Scarlets), Jonathan Davies (Scarlets), Jamie Roberts (Cardiff Blues), Shane Williams (Ospreys); Rhys Priestland (Scarlets), Mike Phillips (Bayonne); Paul James, Huw Bennett, Adam Jones (all Ospreys), Luke Charteris (Newport Gwent Dragons), Alun Wyn Jones (Ospreys), Dan Lydiate (Dragons), Sam Warburton (Blues, capt), Toby Faletau (Dragons).
Replacements: Andy Powell (Sale Sharks) for Lydiate (9), Leigh Halfpenny (Blues) for Hook (40), Lloyd Burns (Dragons) for Bennett (61), Gethin Jenkins (Blues) for James (61), Bradley Davies (Blues) for AW Jones (68).
Not Used: Tavis Knoyle, Scott Williams (Scarlets).
Replacements: Lloyd Burns (Dragons), Gethin Jenkins, Bradley Davies (both Blues), Andy Powell (Sale Sharks), Tavis Knoyle, Scott Williams (both Scarlets), Leigh Halfpenny (Blues).
Samoa: Paul Williams; Sailosi Tagicakibau, George Pisi, Seilala Mapusua, Alesana Tuilagi; Tasesa Lavea, Kahn Fotuali'i; Sakaria Taulafo, Mahonri Schwalger (c), Anthony Perenise, Daniel Leo, Kane Thompson, Ofisa Treviranus, Maurie Faasavalu, George Stowers.
Replacements: James So'oialo for Tagicakibau (55), Joe Tekori for Leo (68), Jeremy Su'a for Lavea (68), Eliota Sapolu-Fuimaono for Mapusua (69), Census Johnston for Perenise (69), Ti'i Paulo for Schwalger (72), Manaia Salave'a for Trevaranius (76).
Referee: Alain Rolland (IRFU)
Touch judge: Romain Poite (France)
Touch judge: Jérôme Garces (France)
TV match official: Giulio De Santis (Italy)