Fiji went down to a shock 24-23 defeat by Portugal in Toulouse on Sunday but still qualified for a Rugby World Cup quarter-final with England and ensured the elimination of Australia.
Fiji, who only needed one point from the game, finished runners-up in Pool C behind Wales and will play the English, whom they beat at Twickenham in both sides' final World Cup warm-up match, in Marseille, a day after the Welsh take on Argentina at the same Stade Velodrome.
The result of the 40th and final pool game of the tournament in France also saw Eddie Jones' Wallabies finish in third spot to miss out the knock-out phase for the first time.
The Fijians looked out of sorts in a nervy display marred by a number of handling errors under intense pressure from Portugal, whose victory — thanks to a converted try two minutes from time — was their first at a World Cup.
"It is incredible and unbelievable," said Portugal coach Patrice Lagisquet. "The players always find resources that I never expected.
"That last try, it was amazing. They still surprise me after four years and it is an incredible group."
Fiji coach Simon Raiwalui heaped praise on Portugal.
"They stuck in and got the try at the end, full credit to them," he said "We're disappointed to not get that win, we were a bit tired in terms of context of the game, but Portugal can enjoy tonight."
Turning to England, Raiwalui added: "We have got to reassess tomorrow and recover, they are a very good tournament team England — but we will review it first."
Fiji scrum-half Frank Lomani got the scoreboard ticking with an early penalty in a high-tempo start to the game, with the Pacific Islanders looking to build on wins over Australia (22-15) and Georgia (17-12) after an opening 32-26 defeat by Wales.
But Portugal, with the ubiquitous Samuel Marques marshalling his team, gave as good as they got in the early skirmishes.
Portugal came into the game winless, having lost to Wales (28-8) and Australia (34-14) either side of an 18-18 draw with Georgia.
And as the game opened up towards the end of the first-half, it was the Portuguese who took the game by the scruff of the neck, Rodrigo Marta going close on a kick and chase before an attack marked by a number of offloads led to them kicking for touch as they searched for a score.
The ball was recycled but star winger Raffaele Storti knocked on over the line as he chased down a pass that came off his toe.
Marques kicked the penalty to draw the scores level after a previous Fijian infringement.
The game turned on its head in 10 crazy minutes in the second period.
Storti enjoyed a successful second bite of the apple, outpacing Vinaya Habosi to latch on to a Pedro Bettencourt grubber after Jeronimo Portela outjumped everyone to gather a high up-and-under.
Marques converted, but from the restart chaos ruled, Marta breaking two tackles and sprinting upfield. The winger found Nicolas Martins inside, but the flanker's pass went to ground and was scooped up by Fiji full-back Sireli Maqala.
Maqala surged back into Portuguese territory and when he was pulled to ground, Levani Botia crashed over, Lomani converting to make it 10 points apiece.
When Botia was yellow carded almost immediately after for a high tackle on Portela, Portugal ripped back and veteran prop Francisco Fernandes was driven over for his side's second try. Marques made no mistake with the conversion.
Fiji responded, dominating possession and territory, but a driving double tackle by Fernandes and Martins on Te Ahiwaru Cirikidaveta and hooker Mike Tadjer forcing Habosi into a knock-on in contact were symbolic of Portugal's doughty defence.
Mesake Doge finally broke the deadlock, crashing over with 12 minutes to play, Lomani converting to level the scores once again.
The Fijian scrum-half was then on target with two penalties that looked to have handed Fiji the win.
But Marta crossed for a try with two minutes to play, Marques delivering the coup de grace conversion for a famous victory.