Portugal qualified for the round of 16 at the World Cup despite being held 1-1 by Iran in World Cup Group B on Monday after Cristiano Ronaldo missed a penalty.
The European champions, needing a draw to qualify, went ahead with a stunning Ricardo Quaresma goal in the 45th minute.
Ronaldo had a chance to extend the lead when he won a penalty in the 51st minute but Iran goalkeeper Alireza Beiranvand dived to his left to save his effort from the spot.
Karim Ansarifard equalised with a stoppage time penalty awarded after a video review.
However, Portugal clung on to finish second in the group with five points behind Spain, who drew 2-2 with Morocco, on goals scored, and will meet Uruguay in the last 16.
Ronaldo had his penalty saved and could have seen red in an incident packed Group B match.
Having scored four goals already this tournament, Ronaldo looked to silence Iran this evening in Saransk - but even he couldn't net from the spot after VAR handed him a second half penalty.
And as his frustration grew he saw yellow for striking Omid Ebrahimi in the face after another VAR review.
IRAN: Beiranvand 6; Rezaeian 7, Pouraliganji 6, Hosseini 6, Hajsafi 6 (Mohammadi 56, 6); Taremi 7, Jahanbakhsh 6 (Ghoddos 70, 6), Ezatolahi 6 (Ansarifard 76, 7), Ebrahimi 6, Amiri 7; Azmoun 7.
PORTUGAL: Patricio 6; Soares 6, Pepe 7, Fonte 7, Guerreiro 6; Carvalho 6; Adrien Silva 6, Joao Mario 7 (Moutinho 84, 5), Quaresma 8 MOTM (Bernardo Silva 70, 6); Ronaldo 6, Andre Silva 6.
Referee: Enrique Caceres (Paraguay)
See the latest in-play odds at Betfair - click here .
FULL-TIME: IRAN-1-1 PORTUGAL
The results mean that Portugal's easier-on-paper tie with Russia does not come to pass; instead, Spain top the group and will face the hosts in the round of 16. Ronaldo and company must face Uruguay instead, unbeaten at the 2018 World Cup - and for Iran, it is heartbreak as they pack their bags and head home. Until the next time then, thank you for joining us - and have a good week!
Ricardo Quaresma's beautiful first-half strike is cancelled out by a VAR penalty from Karim Ansarifard - but it is not enough for Iran as Portugal progress from Group B to the knockout rounds. The substitute's late goal is enough to consign Fernando Santos' men to second however as Spain tie 2-2 with Morocco - meaning Cristiano Ronaldo, who missed a penalty, will face off against Uruguay in the round of 16. Full-time in Saransk at the end of a frantic game; Iran 1-1 Portugal.
Cedric gets booking after the whistle in a farcical finish to this game as tempers continue to boil over.
Andre Silva is replaced by Goncalo Guedes with the final change of the game.
Taremi puts it into the side netting for Iran! My word, that could have been history as, from close range, he squeezes his shot the wrong side of the left post.
ANSARIFARD SCORES! 1-1! The substitute almost misses as he puts it high and the ball flies into the roof of the netting on the right side. Suddenly, Iran have a chance. VAR has rescued them here. All square in Saransk.
The penalty is given! Iran have a chance to equalise here, with Ansarifard to take.
Are we getting another VAR penalty? The referee, after much delay, is off to the touchline to look at a potential handball against Cedric. Four added minutes.
Ronaldo gets taken out with an Ansarifard tackle out on the left wing and duly swings it in, with Rezaeian the man to clear before a header can come in.
This has been a highly energetic, rather fractious game between the pair tonight, but as it stands, Iran are heading out of the World Cup at the group stage once more. Portugal are currently headed for the knockout stages - and a match with Uruguay or Russia.
Should Ronny have seen red?
Cristiano Ronaldo got a yellow card after a VAR call on this challenge.
He seemed catch Iran’s Omid Ebrahimi in the face.
Was a yellow the right call?
Joao Moutinho replaces Mario now for Portugal's second change of the game.
It's a booking for Ronaldo after the referee returns to the pitch, which he can't quite believe. The tackle itself was something of nothing, and the Portugal captain may feel hard done by there.
Ronaldo brings down Pouraliganji as the pair jostle for a ball out on the left wing, deep in Iranian territory now and the referee heads to the VAR to look for a possible red card after replays show that the Portugal captain caught the defender on the face with his hand.
Amiri wins a free-kick out on the left wing for Iran after Cedric catches him with a nippy challenge but Portugal defend it cleanly and break back downfield with Ronaldo.
Silva goes for goal from distance and hooks it well wide to the right. Portugal still have the lead but they've not come close to an equaliser really since Ronaldo's penalty.
Karim Ansarifard is the final change for Iran, as he replaces Ezatolahi.
As Iran flag in midfield, so too do Portugal; their game management is becoming increasingly sloppy, with a few loose passes opening it up more than they would want. Azmoun nearly gets a boot to a loose pass in the opposition box, but goes down under pressure from Carvalho and Pepe clears.
Ghoddos! My word, that was close from the substitute. A long ball played to Azmoun is nudged to him and he blasts a shot wide by a couple of inches at the left post from 20 yards out.
Ronaldo cuts around the Iranian midfield and towards the opposition box with ease on the left, but strong work by the back four force him to cut wide before he skews his shot out at the right post.
A change for both sides now with 20 minutes left on the clock; Quaresma - on a booking - is replaced by Bernardo Silva...
...and Iran take off Jahanbakhsh and bring Saman Ghoddos on.
Cristiano Ronaldo's penalty in pictures
Want to relive Ronaldo’s penalty miss.
Well, here he goes down...
And then he takes it...
Then it’s saved...
And he’s not happy...
There's a touch of fatigue setting into Iran right now as Portugal slip round them with ease again through Adrien Silva. They aren't going down without a fight still though; Jahanbakhsh intercepts and sweeps a long cross in for Taremi that Cedric heads away.
An awful tackle from Quaresma! He absolutely clatters Ezatolahi on the cusp of halfway and the referee books him - but the Portugal man is lucky to not be sent off for that.
There's a pause in play after goalscorer Quaresma goes down at the edge of the Iran box. The Portugal man does not appear to be seriously injured and on the touchline, Queiroz is frustrated by the stoppage.
Guerreiro goes for goal himself from outside the Iran box, only to see it deflected straight back to him off Pouraliganji. This second-half is an utterly enthralling encounter, even more so than the first with that penalty save.
The energy levels between both sides has ramped up massively since half-time as Iran seek those two goals. They've only ever managed to score more than once on a single occasion in their World Cup history; against the USA at France 1998.
The Iranian captain is the first man to be substituted in this game as his manager Queiroz is ordered back into his technical area following his departure to address his players after Azmoun's yellow card. Milad Mohammadi is the replacement,