Wales qualified for the Rugby World Cup quarter-finals as Josh Adams scored a hat-trick to earn Warren Gatland's side a 29-17 success over Fiji in Oita.
The Fijians raced into a 10-0 lead thanks to tries from Josua Tuisova and Kini Murimurivalu inside the opening eight minutes, but Adams' first two scores - each converted by Dan Biggar - meant Wales led at the interval of an action-packed contest that featured a slew of disallowed tries and yellow cards.
A penalty try nudged Fiji back in front before, after Rhys Patchell levelled matters with a long penalty, Adams sealed his treble on the hour mark following brilliant work from Jonathan Davies.
Liam Williams' bonus-point try made sure of the victory which is likely to pave the way for Wales to clinch top spot in Pool D, while Fiji's defeat meant they were eliminated and guaranteed Australia would go through to the final eight.
It was Fiji who flew out of the blocks in a wild first half that featured four tries, another quartet of disallowed scores and a trio of yellow cards.
Tuisova was the first to go over with a fine solo effort as he barged past Adams before holding off Biggar and Josh Navidi to reach for the line and dot down.
Both teams then had scores ruled out - Wales' try through Navidi chalked off due to a knock-on before the TMO spotted a forward pass prior to Frank Lomani going in.
Fiji may not have got a second try there but they did gain a man advantage as Ken Owens flipped Viliame Mata onto his back in the build-up to earn a sin-binning, with Murimurivalu bouncing off Adams and rolling over the line to make it 10-0.
Ben Volavola missed his second conversion, though, and a shoulder-led charge from Tevita Cavubati at a ruck meant he was also sin-binned.
Adams took advantage by collecting Biggar's kick to get Wales on the board and he thought he had a second shortly after, only for the TMO to rule that out as his left foot just went into touch thanks to a brilliant Lomani tackle.
Relentless Welsh pressure resulted in Semi Kunatani being yellow-carded and Wales made use of men over on the left as Adams went in again, with Biggar crucially remaining perfect with the boot.
There were further Fijian tries disallowed either side of the interval for forward passes, but they did regain the lead 13 minutes into the second half from a penalty try, which came following a driving maul shortly after James Davies' caution left Wales undermanned.
A nasty collision between Biggar and team-mate Williams resulted in the former going off, with Patchell coming on and duly slotting over a 42-metre penalty to make it 17-17.
Then came the moment of the match, Davies dumping Jale Vatubua down with a brilliant hand-off and then flipping the ball out to Adams as he was tackled, the wing having the awareness to stay in touch and complete his hat-trick.
A ragged Fijian defence then allowed Gareth Davies to burst through a gap and set up Williams to seal the bonus point.