Oita - Winger Josh Adams scored a sensational hat-trick on Wednesday as Wales booked a Rugby World Cup quarter-final place with a 29-17 bonus-point win over Fiji, sending Australia through in the process.
In an end-to-end encounter in Oita, Fiji scored two tries in the first eight minutes playing some free-flowing rugby, but the Six Nations champions pegged them back and a Liam Williams try with 12 minutes left buried the Fijians' chances.
The result also guaranteed Australia's progress to the last eight ahead of their final Pool D game against Georgia on Friday.
But the victory may have come at a high price for Wales with playmaker Dan Biggar apparently knocked out in an aerial clash with team-mate Williams, and Adams limping off with a knee injury after his third try.
"I think the medics are going to be working pretty hard in the next 24/48 hours. But pleasing to get that bonus-point win," said Wales coach Warren Gatland.
"That was tough, they've got some unbelievable individuals and we just had to stay in it," added Gatland.
Fiji produced a flying start with two tries in a dramatic opening, in which a third try was ruled out by a forward pass and Wales went a man down when hooker Ken Owens was sent to the sin-bin for a dangerous tackle.
It was the first of four yellow cards as referee Jerome Garces lost patience with repeated fouls.
But as the game wore on the superior quality of the Welsh attack told, and forward passes cost Fiji two more tries.
Although the final scoreline was probably closer than Wales would have liked, and Fiji wing Semi Radradra was named man of the match, the Welsh did out-score Fiji four tries to three.
"I think we probably started very slow out the blocks. We knew that if Fiji got their tails up, we were going to be in for a hard day at the office," said Wales captain Alun Wyn Jones.
"Full respect and credit to Fiji. I think we saw the best of them at times today. It's difficult to play against."
Fiji end the tournament with only one win, over Georgia, and if they are to finish third in the pool to automatically qualify for the 2023 World Cup, they will need Wales and Australia to beat Uruguay and Georgia respectively in their final group matches.
But they rocked Wales from the kick-off to take play up to the shadow of the posts where they won a penalty and opted for a scrum. The ball went wide and Josua Tuisova ran over Adams and Biggar to score.
When a Wales chance to score was ruled out after a knock-on, Fiji swept back on the attack and were rewarded with a try to Kini Murimurivalu.
The sting was somewhat taken out of the Fijian attack when a shoulder charge saw lock Tevita Cavubati join Owens in the sin-bin.
With numbers now even on the field, Biggar engineered Wales' first points with a well-weighted cross-kick to Adams who scored in the corner.
After the referee's warning about fouls, Fiji flanker Semi Kunatani was caught offside and sent to the sin-bin and in his absence Wales hit the front with Adams' second try converted by Biggar.
Wales held a 14-10 lead at half-time after Fiji's chance to hit the front again just before the break was wasted when Ben Volavola's pass to an unmarked Viliame Mata floated forward.
James Davies was sent off for 10 minutes for a deliberate off-side 12 minutes into the second half.
Fiji go for a lineout and when Wales pulled down the subsequent drive, Garces awarded a a penalty try to put them back in front.
A minute after Rhys Patchell took the field for the injured Biggar, he landed a 42-metre penalty to level the scores.
A slick back-of-the-hand pass from Jonathan Davies then sent Adams over for his third try to restore the lead for Wales before Williams scored Wales' bonus-point try and seal the win.
Wales 29 (14)
Tries: Josh Adams (3), Liam Williams
Conversions: Dan Biggar (2)
Penalty: Rhys Patchell
Fiji 17 (10)
Tries: Josua Tuisova, Kini Murimurivalu, Penalty Try
15 Liam Williams, 14 George North, 13 Jonathan Davies, 12 Hadleigh Parkes, 11 Josh Adams, 10 Dan Biggar, 9 Gareth Davies, 8 Ross Moriarty, 7 James Davies, 6 Josh Navidi, 5 Alun Wyn Jones (captain), 4 Jake Ball, 3 Tom Francis, 2 Ken Owens, 1 Wyn Jones
Substitutes: 16 Elliot Dee, 17 Rhys Carre, 18 Dillon Lewis, 19 Aaron Shingler, 20 Aaron Wainwright, 21 Tomos Williams, 22 Rhys Patchell, 23 Owen Watkin
15 Kini Murimurivalu, 14 Josua Tuisova, 13 Waisea Nayacalevu, 12 Lepani Botia, 11 Semi Radradra, 10 Ben Volavola, 9 Frank Lomani, 8 Viliame Mata, 7 Semi Kunatani, 6 Dominiko Waqaniburotu (captain), 5 Leone Nakarawa, 4 Tevita Cavubati, 3 Manasa Saulo, 2 Samuel Matavesi, 1 Campese Ma’afu
Substitutes: 16 Tuvere Vugakoto, 17 Eroni Mawi, 18 Peni Ravai, 19 Apisalome Ratuniyarawa, 20 Peceli Yato, 21 Nikola Matawalu, 22 Jale Vatubua, 23 Josh Matavesi