Portugal reached the last 16 of the World Cup as Group B runners-up after a controversial 1-1 draw with Iran in Saransk.
Ricardo Quaresma scored a sublime goal in the 45th minute and Cristiano Ronaldo had a penalty saved in the second half as Portugal appeared to be cruising through as group winners.
But Ronaldo was perhaps fortunate to avoid a red card following an 80th-minute VAR review and Iran equalised through a dubious injury-time penalty from Karim Ansarifard - awarded with the use of VAR for a handball by Cedric Soares - before Mehdi Taremi missed a gilt-edged chance late on to knock Portugal out.
The result, combined with Spain's late equaliser in their 2-2 draw with Morocco - means Portugal will play Uruguay in the next round on Saturday evening, while Iran are eliminated.
Iran: Beiranvand (7), Hajsafi (7), Pouraliganji (6), Hosseini (6), Rezaeian (7), Ezatolahi (7), Ebrahimi (7), Amiri (6), Taremi (7), Jahanbakhsh (7), Azmoun (7)
Subs: Mohammadi (6), Ghoddos (7), Ansarifard (7)
Portugal: Rui Patricio (7), Soares (7), Pepe (6), Fonte (7), Guerreiro (6), Carvalho (7), Adrien Silva (7), Mario (7), Quaresma (8), Ronaldo (6), Andre Silva (6)
Subs: Bernardo Silva (6), Moutinho (n/a), Guedes (n/a)
Man of the match: Ricardo Quaresma
A win would have taken Iran through, but after frustrating their opponents for 45 minutes Quaresma struck on the stroke of half-time. He swapped passes with Adrien Silva on the right, before striking sweetly with the outside of his right foot from the edge of the area, giving Ali Beiranvand no chance in the Iran goal.
Portugal were given a penalty eight minutes after half-time when Ronaldo skipped past a pair of defenders and went down under a challenge from Saeid Ezatolahi. Paraguayan referee Enrique Caceres initially waved away the appeals, but eventually awarded the spot-kick after the VAR recommended he review the incident.
However, Ronaldo's penalty was well saved by Beiranvand, who dived to his left and gathered the ball at the second attempt, frustrating the Real Madrid star's hopes of catching England's Harry Kane at the top of the Golden Boot standings.
Joao Moutinho (illness) was replaced in Portugal's midfield by Leicester's Adrien Silva. Ricardo Quaresma and Andre Silva also started as Fernando Santos made three changes. Alireza Jahanbakhsh replaced Karim Ansarifard in Iran’s only change.
The second half became increasingly ill-tempered and Ronaldo avoided a red card when VAR asked the referee to review his off-the-ball swing of the arm at in the direction of Morteza Pouraliganji 10 minutes from full-time. After watching replays at the side of the pitch, Caceres decided a booking was sufficient.
However, Portugal were frustrated by a VAR decision in injury-time when Sardar Azmoun headed a corner onto the arm of Soares at close range. After a three-minute delay, the referee controversially awarded a penalty which was lashed into the roof of the net by Ansarifard (90+3).
And there was further drama when Taremi looked certain to score the winner that would have taken Iran through a minute later, but hit the side netting from six yards instead of scoring what would have been the most famous goal in his nation's history.
Portugal, who were top of the group going into injury-time, survived a chaotic climax and must now re-focus ahead of their knock-out clash in Sochi on Saturday.
- Portugal have progressed from the group stage of the World Cup for the fourth time in their history.
- Iran have been eliminated from the group stage at the World Cup in all five tournaments they've competed in.
- Both of Iran's goals at the 2018 World Cup were scored in injury time (94:06 against Morocco, 92:48 against Portugal).
- Two of Cristiano Ronaldo's three penalties at the World Cup for Portugal have been against Iran - he scored in 2006 but saw his effort saved in this game.
- Cristiano Ronaldo has a 50 per cent penalty success rate in major tournaments for Portugal, scoring two, but also failing with two.
- Iran's goal - scored after 92 minutes and 48 seconds - was the latest goal Portugal have ever conceded at the World Cup.
- Portugal have never lost a World Cup match when they've scored first (W13 D3).
Man of the match - Ricardo Quaresma
This was a match full of drama and controversy - in which the key figure was the Paraguayan referee and his assistants in Moscow. However, the one moment of quality in the match came from the right foot of Quaresma. Portugal had been frustrated by a well-disciplined Iran side for 45 minutes and had barely had a shot at goal before the Beskitas forward struck a sublime curler that turned the match on its head and prompted the second-half drama. Quaresma was substituted after a running battle with Saeid Ezatolahi after the break, but the veteran's goal on his first World Cup start will live long in the memory.
Iran's World Cup is now over, while Portugal will face Uruguay in Sochi on Saturday evening (7pm kick-off) as they bid to reach the quarter-finals.