Winger Josh Adams grabbed a hat-trick of tries as a battered and bruised Wales battled to a 29-17 bonus-point win over Fiji to book their place in the Rugby World Cup quarter-finals.
In a frenzied clash under the roof at Oita Stadium, Warren Gatland's team lost talismanic flyhalf Dan Biggar to a head injury for a second time in the tournament shortly after the Fijians surged into the lead early in the second half of the Pool D clash.
A penalty try to Fiji produced a huge scare for Welsh fans who hold bitter memories of the 'Nightmare in Nantes' when the Pacific islanders knocked them out of the 2007 World Cup.
But Adams steadied the ship with his hat-trick try on the hour-mark and fullback Liam Williams crossed 12 minutes from the siren to settle the game.
The result ensured Wales, with 14 points, leapfrogged Australia (11 points) to top the pool ahead of their final clash against emerging nation Uruguay.
But the Welsh, with England or France awaiting them in the quarter-finals, will be counting the cost, with Adams and Jonathan Davies also suffering injuries.
Wales had been rejuvenated after a 10-day break and, having enjoyed fast starts in their wins over Georgia and Australia, coach Warren Gatland had asked for another in Oita.
Instead it was Fiji charging out of the blocks.
A penalty for offside by flanker James Davies brought the ball to the five-metre line and Fiji spread the ball wide from a scrum to winger Josua Tuisova, who bashed through Adams and Biggar to plant the ball next to the right corner flag.
Wales responded immediately when backrower Josh Navidi went over after a turnover but the try was cancelled by the TMO due to a knock-on. Fiji crossed again moments later, but scrumhalf Frank Lomani's try was also scratched by the TMO after a forward pass.
Worse was to come for Wales when hooker Ken Owens was yellow-carded in the eighth minute for flipping number eight Viliame Mata on his back in an ugly tackle.
The barnstorming Semi Radradra, named player of the match, made Wales pay at once, setting up a try for fullback Kini Murimurivalu in the right corner.
Flyhalf Ben Volavola failed to covert either try, however, and Fiji's gains were further squandered by lock Tevita Cavubati who was yellow-carded for a shoulder charge in the 17th minute.
Biggar wasted no time setting up Wales' first try with a sumptuous cross-kick to Adams. Wales' forwards then ramped up the pressure and Fiji's scrambling defence was soon on the brink of collapse.
Flanker Semi Kunatani saw yellow for a fourth off-side penalty and soon after Adams was strolling over for his second five-pointer as the Welsh sliced open Fiji's threadbare right flank.
Fiji were fortunate to trail by only four points at 14-10 at the break but blew a chance to retake the lead in the 49th minute with another forward pass disallowing a try for Radradra.
The game turned on its head minutes later, however, as Davies was yellow-carded for a ruck infringement.
Fiji kicked for the corner, rumbled a lineout drive to the line and were awarded a penalty try after Wales collapsed the maul.
A shudder went through the Welsh crowd when Liam Williams clattered into Biggar as both attempted to catch a clearing kick. After several minutes of medical attention, Biggar groggily got to his feet and jogged off the field.
His replacement Rhys Patchell stepped up to slot a 42-metre penalty and minutes later Adams had his hat-trick, again at the corner following a stunning linebreak by Davies.
Fiji provided plenty of highlights but were guilty of a defensive blunder late on as scrumhalf Gareth Davies cantered through a hole to set up Williams for the sealing try.
Follow Ireland v Samoa on Saturday 12 October (kick-off 11.45am) via the live blog on RTÉ.ie/Sport and the News Now App, watch live on RTÉ2 or listen to live match commentary on RTÉ 2fm.