Iceland continued their fairytale run at Euro 2016, while Portugal needed some Cristiano Ronaldo magic to make sure their campaign continued.
Iceland snatched a stoppage-time winner to make it through to the last 16 after a deserved 2-1 victory against Austria in Paris in their final Group F match.
Iceland end their section second with five points. Austria go out with one point.
In humid conditions at the Stade de France, the islanders had the better chances in the early stages taking the lead in the 18th minute when Jon Dadi Bodvarsson coolly steered the ball home after a flick-on in the box.
Austria, who missed a penalty in the first half and laid siege to Iceland's goal in the second, gave themselves hope when Alessandro Schopf scored in the 60th minute, but Arnor Traustason secured the win in stoppage time.
Iceland will play England in the last 16.
Meanwhile the Lyon, Ronaldo delivered two goals and an assist to secure the 3-3 draw Portugal needed against already qualified Hungary to ensure progress to the knock-out stage.
Zoltan Gera gave Hungary the lead after 19 minutes and captain Balazs Dzsudzsak found the net with two deflections early in the second half in Lyon.
But Portugal equalised each strike with Ronaldo setting up Nani before the break and then finding his first goals in the tournament after the interval. The first was a stunning flick from Joao Mario's cross and the second a powerful close-range header.
Hungary progress as Group F winners on five points and face the runners-up from Group E, likely to be Belgium, in the last 16 while Portugal, on three, go through in third-place to meet Croatia.