Wales had to grind out the tension-filled victory from a 10-6 deficit at halftime, pulling ahead with two penalties by replacement kicker Rhys Priestland then scoring the decisive try 12 minutes from the end to Shane Williams, the diminutive winger's 55th in 83 tests.
"We showed some great character, the boys dug deep in the second half," Wales coach Warren Gatland said. "Twelve months ago we might not have won that game. We've worked really hard the past few months and it's going to show people how much it means to us to get out of this and to get a 'W' on the board."
The win finally ended Wales' hoodoo against Manu Samoa, who had humbled them in the 1991 and 1999 World Cups.
Samoa was backing up four days after beating Namibia in Rotorua, and visibly tired in the second half but didn't use that as an excuse.
"We're very disappointed in the result," lock Daniel Leo said. "The short turnaround from Wednesday caught up with us in the last 15 to 20 minutes. The legs started getting heavy."
The Welsh sensed that in the second half.
"At halftime there was no panic," captain Sam Warburton said. "We thought we'd have the fitness and knew if we kept the ball, stayed patient and didn't force anything the points would come."
Samoa played more like a European side, effectively employing 12-man rugby and pick-and-go's to score the only try of the first half when prop Anthony Perenise drove over on the stroke of halftime. Paul Williams kicked two goals to match a pair by James Hook, who didn't return after the break because of a shoulder injury.
After being unlucky to lose to defending champion South Africa by a point, Wales knew it had to win to stay in playoff contention. It responded with another gritty effort, making 142 tackles against a tough Samoan outfit, many of whom were familiar to the Welsh in European club competitions.
Samoa's road to reaching the quarterfinals for the first time since 1995 became considerably harder because it still has to face Fiji and South Africa, and both matches are only five days apart.
"We're still there. I've got belief in my team," captain Mahonri Schwalger said. "We'll make the quarterfinals if we win the next two games, so it's not over for us."
Samoa had to make a late shuffle when goalkicking flyhalf Tusi Pisi and flanker Taiasina Tuifu'a failed to recover in time from injuries against Namibia and were dropped from the 22.
Still, 13 ran on from the side which beat Australia in July. The big surprise was the role-reversal in terms of strategies.
Samoa safely kicked for territory and kept it tight to the point where destructive left wing Alesana Tuilagi touched the ball only once in the first 30 minutes. By contrast, Wales looked more Polynesian by trying to run out of its 22, give work to big, young wing George North, and making all the big hits. North flattened Samoa flyhalf Tasesa Lavea, and inside centre Jamie Roberts elbowed opposite Seilala Mapusua onto his back.
Paul James' work on Samoa tighthead Perenise gave Wales the edge in the scrums, and Wales enjoyed plenty of ball in the first half with seven penalties. But it never looked like scoring a try. Instead, it relied on Hook's two penalties, each time putting Wales in front.
Samoa threatened throughout, but winger Sailosi Tagicakibau and No. 8 George Stowers both knocked on in front of the line.
Disinclined to spread the ball wide, Samoa smashed into the Welsh line to move it back three meters at a time. It was unlucky when one seemingly 15-phase effort ended with flanker Maurie Fa'asavalu penalized for a double movement on the tryline in the 30th.
But Samoa started all over again, and just before the half, after another multiphase attack, Samoa switched left across the posts, North over-ran the ball and Perenise barged over under two tackles.
The match opened up in the second half, and flyhalf Priestland soon landed a 45-meter penalty off the crossbar to narrow the deficit to one. He put Wales in front with his second penalty in the 65th.
Halfpenny, on for Hook at fullback, produced the decisive try in the 68th out of nowhere. He took in a punt 30 metres out from his line, evaded three Samoans and hared off down the left touchline. He exchanged passes with centre Jonathan Davies, ran into the 22 and lobbed a pass on his outside which bounced off the ground and into a streaking Shane Williams, who dotted down his Welsh-record eighth World Cup try.
Wales 17 (Shane Williams try; James Hook 2 penalties, Rhys Priestland 2 penalties), Samoa 10 (Anthony Perenise try; Paul Williams conversion, penalty). HT: 6-10.