A scrappy Wales was made to work hard for victory against Uruguay but prevailed with a bonus point 35-13 win on Sunday to top Pool D and set up a quarterfinal with three-time finalist France.
Wales clung to an eight-point lead with seven minutes left until a strong carry by Leigh Halfpenny scattered the Uruguayan defense and opened up a hole for Tomos Williams to settle the matter with the bonus-point try.
Coach Warren Gatland was a picture of discontent for much of the evening as his team was denied four tries, including two from forward passes.
"We know we have to do a lot better than that. But we have to be happy that we came away with a bonus-point win," said flanker Justin Tipuric, who led the side for the first time in place of regular rested skipper Alun Wyn Jones.
"You have to give Uruguay credit. They didn't stop from the beginning to the end and they're a tough bunch of boys."
Uruguay bowed out of the World Cup with huge satisfaction having earned plenty of respect from Tier 1 nations and also upset Pacific power Fiji earlier in the tournament.
"There were areas where we were able to play how we wanted and we were also able to shock Wales," said coach Esteban Meneses.
"We were able to show how we have developed Uruguayan rugby."
The Welsh had come into match with 13 changes and a patched-up backline with Dan Biggar sidelined after his second head knock of the tournament and flanker Justin Tipuric standing in as captain for the rested Alun Wyn Jones.
A moment of silence was held before the game for victims of Typhoon Hagibis, which pounded into Honshu on Saturday.
Wales dominated possession in the early exchanges but its attacking raids were stopped by some dogged Uruguayan tackling and a slew of handling errors.
Flanker Aaron Shingler broke through on the right wing to plant the ball by the flag in the 11th minute but the try was disallowed as he was well outside the touch line.
With its tryline under siege, Uruguay's resistance broke in the 17th minute as prop Nicky Smith was driven over the line.
Uruguay responded well and almost hit back with its own try minutes later, but a long pass from Felipe Berchesi drifted forward to winger Leandro Leivas on penalty advantage and Berchesi kicked for three points instead.
Wales was denied a second try in the 25th minute, with Hadleigh Parkes putting winger Hallam Amos over with a forward pass.
Not even a chorus of singing from Welsh fans could help Gatland's side as it turned over the ball deep in Uruguay's 22 and gave Berchesi a second penalty in front of the posts.
It was all back-slapping and smiles among the Uruguayans as they jogged off with only a 7-6 deficit at halftime.
Wales rebooted after the break, testing Uruguay with the high ball.
Bradley Davies was bundled back over the line near the posts by the desperate Uruguayans but the big lock's strong carry created an overlap out wide and an unmarked Josh Adams cantered over at the left corner after a long pass from Rhys Patchell.
Wales was threatening to break the game open, but the scrappy play returned as Parkes' horror night continued.
The inside center blew a third try for Wales by putting Amos over the line with another forward pass.
A yellow card to Uruguay flanker Santiago Civetta eased the pressure and paved the way for a penalty try as Wales rumbled a maul toward the line.
Yet Uruguay rallied brilliantly, with hooker German Kessler diving over from in close to throw a scare through the Welsh in the 71st minute.
Wales rose to the challenge as Williams grabbed the bonus-point try but was left red-faced minutes later when winger Amos spurned another try when he failed to plant the ball correctly when doing a flamboyant swan dive.
In a madcap finish, Gareth Davies ensured Wales finished on a high note as he burned away from the Uruguayan defenders after a turnover to cross under the posts.
With your current subscription plan you can comment on stories. However, before writing your first comment, please create a display name in the Profile section of your subscriber account page.