Cristiano Ronaldo scored twice as Portugal registered a 3-3 draw against Hungary on Wednesday to earn a place in the knockout stages at Euro 2016.
Zlotan Gera opened scoring for Hungary in the 17th minute but Nani equalised three minutes before half-time.
Hungary went ahead again through Balazs Dzsudzsak in the 47th minute.
Ronaldo, who struggled in the first two games, finally broke his Euro 2016 duck with a brilliant flick in the 55th minute to make it 2-2.
Dzsudzsak made it 3-2 for Hungary but Ronaldo once again came to Portugal's rescue with the final equaliser.
Portugal came from behind on three occasions but it was only enough for third place after Iceland scored a 94th-minute winner against Austria in Paris for a 2-1 win.
That goal leaves Hungary topping Group F, while Portugal will have to make do with a clash with Croatia in Lens on Saturday night.
Iceland finished second and set up a round of 16 clash with England.