Cristiano Ronaldo scored two trademark brilliant goals Wednesday to go into European Championship history and rescue Portugal in a 3-3 draw that took them into the last 16.
The 31-year-old opened his account in style with a deft backheel flick on 50 minutes, then a bullet header 12 minutes later to twice equalise at the Stade de Lyon.
The result left Hungary on top of Group F. Portugal squeezed through as one of the best third-place finishers but now face a tough match against Croatia.
The Real Madrid ace became the first player to score at four European championship finals and his 17th match in a Euro tournament was also a record.
It was his 128th appearance for Portugal, further extending the record he set last Saturday, as he made a record 17th appearance at Euro finals.
Hungary captain Balazs Dzsudzsak matched Ronaldo by netting two second-half goals as the Mighty Magyars took first place in Group F winners. With three draws, Portugal advance as third behind Iceland.
Hungary took the lead in sweltering conditions at the Stade de Lyon when veteran midfielder Zoltan Gera unleashed a thunderbolt giving Portugal goalkeeper Rui Patricio no chance on 19 minutes.
Nani had the ball in the Hungary net five minutes from the break, but his effort was ruled offside. The Fenerbahce forward was not to be denied and his crisp finish, after a lovely pass in from Ronaldo, put Portugal level on 42 minutes.
The game burst into life with four goals in the opening 20 minutes of the second-half.
Hungary regained the lead just two minutes after the break when Dzsudzsak's well-struck free-kick took a slight deflection off the Portugal wall on 47 minutes.
The stage was set for Ronaldo.
The Real superstar made sure he would leave the Stade de Lyon with two records when he flicked his shot past Kiraly on 50 minutes to make it 2-2.
But Portugal's second equaliser only served to galvanise Hungary's resolve.
Dzsudzsak drilled a free-kick off the wall, but pounced on the rebound and his left-footed shot deflected off Nani, past Rui Patricio, into the far corner on 55 minutes for a 3-2 lead.
There was, however, no denying Ronaldo.
Just moments after coming on, Ricardo Queresma fired in a corner and Ronaldo drove his header past Kiraly on 62 minutes.
By now it was end-to-end stuff as Hungary's attacking midfielder Akos Elek hit the woodwork on 64 minutes as it stayed 3-3 at the final whistle.
Meanwhile, Iceland continued their fairytale story by making it through to knockout stage after a stoppage-time winner gave them a deserved 2-1 victory against Austria in their final group match on Wednesday.
Substitute Arnor Ingvi Traustason scored from close range deep into added time after collecting a though ball from Elmar Bjarnasson following a swift counter-attack.