Portugal registered a 3-3 draw against Hungary to earn a place in the knockout stages at Euro 2016.
In what turned out to be the match of the tournament so far, 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.
Portugal went into the game eager to show their true ability having only secured draws during their first two matches but it was more of the same during the opening 15 minutes as they failed to turn possession into chances.
They were eventually made to pay by a Hungary side brimming with confidence but it took some strike to beat goalkeeper Rui Patricio as Zoltan Gera found the bottom corner with a half-volley from 25 yards out.
The goal stunned Portugal and they almost conceded a second soon afterwards when Akos Elek received the ball inside the penalty area but his left-footed strike was well beaten away by Patricio.
Cristiano Ronaldo had cut a frustrated figure in attack but his quick-thinking resulted in Portugal finding an equaliser as Nani latched onto a pin-point pass from the Real Madrid star before driving the ball inside the near post from 10 yards.
Hungary were second best just before the break but they needed less than two minutes to regain the lead through Balazs Dzsudzsak, who found the top corner of the net with a free kick, although his effort took a deflection off Andre Gomes in the wall.
Portugal needed an immediate response and they got on through Ronaldo, who found the bottom corner after flicking the ball between his legs after being found by Joao Mario but five minutes later, Hungary were back in front.
Both teams were playing at a relentless pace and it took only seven minutes for Portugal to equalise for a third time with Ronaldo getting on the end of a delightful cross from Ricardo Quaresma to head into the far corner.
However, after Austria equalised against Iceland in Paris, Hungary began to sit back and invite pressure from Portugal but their opponents were unable to create a clear-cut opportunity with Ronaldo volleying the best of them into the ground.
Neither side created a significant chance in the closing stages which left it looking like a showdown with England for Portugal but Iceland’s last-gasp winner against Austria left Hungary to go through as group winners and Portugal having to be content with third position.