A 17-10 victory at Waikato Stadium means Wales remain on course for a World Cup last-eight clash - probably against Ireland - in Wellington on October 8.
Samoa, though, threatened to inflict a hat-trick of World Cup calamities on Wales following their wins in the 1991 and 1999 tournaments, until wing Shane Williams scored his 55th Test try.
Williams struck 13 minutes from time, finishing off a flowing move started by substitute full-back Leigh Halfpenny, as Wales overcame an alarming 10-6 interval deficit.
If they can see off remaining group opponents Namibia and Fiji, then that should be enough to march on, especially as Samoa have yet to face world champions South Africa.
It was neither fluent nor pretty and had shades of an underwhelming 17-13 success against the South Sea Islanders in Cardiff two years ago, yet Wales prevailed after a game coach Gatland conceded might not have gone their way in the past.
But they could yet be left to count the cost as fitness updates are awaited on full-back James Hook (shoulder) and flanker Dan Lydiate (ankle), whose injuries will require scans.
Initial reports on Lydiate are not thought to be encouraging, and it is understood he could face a fitness race to make the quarter-finals should Wales progress that far.
"I thought we showed some great character," said Gatland, after presiding over Wales' first World Cup appearance in his home town.
"A few years ago, or 12 months earlier, we might not have won that game. We will dissect the performance over the next couple of days and see where we can improve.
"In the first half, we tried to play a bit too much rugby, but our whole World Cup was about going out in that second half and digging deep. And they did that.
"I thought our conditioning was great. The longer the game went on, the stronger and fitter we looked.
"We knew this was a must-win game, and (a quarter-final place) is in our own hands isn't it?"
On the 10th-minute loss of Lydiate, Gatland added: "He has rolled his ankle. He was a big loss to us defensively.
"The number of tackles he makes, he's a player that doesn't get a lot of recognition. He cannot put any weight on (the ankle) so we will see in the next 24 to 48 hours."
Wales made 142 tackles during the match and prevented Samoa from scoring in the second period, which represented a colossal collective effort not lost on captain Sam Warburton.
"I don't think you can fault the attitude of the players," said Warburton, who dedicated Wales' win to the families of four miners killed at Gleision Colliery near Pontardawe earlier this week.
"I think at half-time there was no panic. We knew we had the fitness levels to take it to 80 minutes.
"We said if we lost the chances are we were probably going home, so there was a lot of pressure on the boys.
"Both sides didn't disappoint - we knew it was going to be an immensely tough battle. Samoa are very physical, and it was a tough game for us.
"We wanted to keep the ball in play as much as we could and back our fitness levels towards the end of the match.
"Leigh (Halfpenny) came on and added some great momentum to the side, and Shane finished it off as we've seen him do a million times before. If our backs get a sniff, they are pretty handy."
Samoa are now left to prepare for a punishing Pool D programme against Fiji and South Africa, with victories required in both games or an early exit is guaranteed.
"We had plenty of ball," Samoa assistant coach Brian McLean said. "We had our chances, but we didn't take them.
"It's going to be really tough, but they (South Africa) probably should have lost to Wales and we gave Wales a bit of a hurry-up, so we will be competitive.
"We just need to be a little more accurate. That is what lost us this game. We are creating opportunities, but the accuracy is down."
And skipper Mahonri Schwalger added: "We have six days to prepare, so we will be fresh and ready for Fiji.
"We will make the quarter-finals if we win the next two games against Fiji and South Africa, so it's not over for us."
Gilbert has released a new line of rugby cleats. The Gilbert Virtuo 8S is part of the exciting new product. Check it out.
The entire All Blacks apparel line has been updated for 2013/14. Check out the New Zealand All Blacks polo.
The Nike Tiempo is a solid rugby cleat and one of few styles still made from full-grain natural leather.
The Gilbert Blitz 8S rugby cleat is a great cleat at a great price of $69.99. Get a new pair of cleats today.
A cool looking all black rugby cleat with the high performance adidas is known for. Get in the Gear!
Wear the crest of the British and Irish Lions on your t-shirt. A great look for the summer.
The All Blacks Performance t-shirt is black with hints of blue from the training jersey. Very Cool.
The New Zealand All Blacks training jersey for 2013/14. Get in the Gear!
The USA Rugby Pro Alternate rugby jersey is perfect for any fan of the Eagles. Get yours to wear during the summer Test matches.
The NEW All Blacks 2013/14 jersey has arrived at World Rugby Shop. Dare to wear the colors of the All Blacks.