Iran held Portugal 1-1 in their final Group B match here on Monday but couldn't stop the reigning European champions from entering the FIFA World Cup pre-quarterfinals.
Ricardo Quaresma gave Portugal the lead in the 45th minute but Iran found the equaliser through a penalty conversion from Karim Ansarifard in the 90+3 minute.
Following the draw at the Mordovia Arena, Iran are third on the table with four points and will now exit alongside Morocco (one point) from Group B. Portugal are second with five points - same as Spain but the latter side is ahead on the basis of scoring more goals during the group stage matches.
With the day's other game of the group, between Spain and Morocco, being played at the same time, the Portugal vs Iran match had a lot of significance in terms of qualifying for the second round and the top position cushion.
Portugal, who started the match with four points - one more than the Asian outfit - had the advantage in case of a draw. And having witnessed the pragmatic style of Fernando Santos' side, the Europeans, though were expected to dominate, gave a signal of first trying to secure the qualification and then going after the top position if chances came.
As a result, the first half between Portugal and Iran saw a slow game, with not many chances created.
However, Iran, bidding to reach the World Cup knockouts for the first time, had a weird start.
They could have conceded the lead in the 10th minute of the match as Joao Mario found himself in front of an open goal thanks to a lack of communication inside the box but he shot over the cross-bar.
Goalkeeper Ali Beiranvand called to clear a cross but defender Saeid Ezatolahi decided to cut it out.
He got no distance on the clearance and then the ball dropped near Mario on the edge of the box but the latter came out with a poor shot.
Beiranvand then went through a period of lapse of concentration as he fumbled the ball a couple of times but his defenders were alert.
Also Portugal didn't press as much as they should have and didn't make the most of the faults Iran made.
Portugal tried to feed their target man Ronaldo but a couple of his free-kicks and headers were not on target and Portugal's slow passing of the ball didn't help their cause.
It did clearly help Iran as they tried to do some clever moves through Sardar Azmoun and Alireza Jahanbaksh.
A Jahanbaksh free-kick was headed towards goal by Ezatolahi, but the effort was straight down the throat of Portugal goalkeeper Rui Patricio in the 34th minute.
Portugal, however, broke the deadlock in the 45th minute when Quaresma played a quick one-two with full-back Cedric Soares, sprinted to the edge of the box before curling a gorgeous outside-of-the-foot finish into the far top corner.
Six minutes into the second half, Portugal could have added a cushion goal after being awarded a penalty after Video Assistant Referee (VAR) found Ezatolahi to have fouled Ronaldo.
But Beiranvand came up with the heroics as he dived to the left to block Ronaldo's penalty to keep Iran alive in the contest and in the World Cup.
Later, Azmoun and Jahanbaksh kept threatening Portugal goal. Azmound also had a couple of penalty shouts rejected until he found one in the third minute of the injury time.
A header from him saw fell on the left hand of Cedric Soares, leading to a penalty from which Iran levelled 1-1. Ansarifard fired to the roof of the net on the right, giving no chance to Patricio.
In the dying moments, Iranian attacking midfielder Vahid Amiri missed a golden chance to score a stunning winner as a long overhead ball saw him through the Portuguese defence but his left-footed flick hit the side-netting, ending their chances in the match.