Portugal came perilously close to a group stage exit from the World Cup during a frenetic stoppage-time period on Monday when unfancied Iran equalised through a penalty and almost scored a winner after Cristiano Ronaldo had earlier missed from the spot, Reuters reports.
The European champions held on to advance to the round of 16 from Group B behind Spain but would now have to take on a much tougher opposition in Group A toppers Uruguay in Sochi on Saturday.
The 1-1 draw, after a stunning Ricardo Quaresma strike was cancelled out by Iran's Karim Ansarifard, meant Portugal finished tied on five points with Spain, who drew 2-2 against Morocco to top the group by scoring more goals.
Spain will next meet hosts Russia at Moscow's Luzhniki Stadium on Sunday.
Portugal were left to rue the missed penalty by their most prolific scorer in the 53rd minute after Iran goalkeeper Alireza Beiranvand pulled off a heroic save to deny them a 2-0 lead.
On the stroke of halftime, Quaresma, making his World Cup debut at the age of 34, played a one-two with Adrien Silva to cut in from the right flank and curled the ball past the outstretched hands of Beiranvand with the outside of his boot.
Iran equalised late on after Paraguayan referee Enrique Caceres used the video assistant referee (VAR) system to rule that Portugal's Cedric Soares had handled the ball in the box.
Ansarifard converted the resulting penalty to level the score, pushing Portugal to second position in the group behind Spain.
A minute later Team Melli came close to sealing their first spot in the last 16 and knocking out their much-fancied opponents but Mehdi Taremi could only hit the side-netting from close range.
"We have achieved our goal and now we have to recover over the next few days to think about the next match," Quaresma told reporters.
"Now we have to continue with this mindset of winning and wait for the next match."
Caceres consulted with VAR to award Portugal a penalty for Morteza Pouraliganji's foul on Ronaldo, Europe's highest international goalscorer, amid vociferous protests from the Iranians and their numerous supporters at the Mordovia Arena.
The Real Madrid forward, however, failed to convert, also losing the chance to tie England's Harry Kane at the top of the scorers' list on five goals. He later escaped a red card after the referee consulted VAR and showed him a yellow for elbowing an opposition player.
Iran were well organised at the back and defended stoically but did not have enough men going forward in the first half.
Carlos Queiroz's men relied mostly on counter attacks and while forward Sardar Azmoun showed plenty of glimpses of his talent, it was not enough to trouble the Portuguese.
"It's such a big disappointment for us," Iran midfielder Alireza Jahanbakhsh said. "We had a big chance at the end of the game, we could have scored and won it. As everyone has seen, we did our best to win this game but we missed some chances."
Portugal had faced a lot of criticism for their lacklustre display and inability to hold possession in their 1-0 win against Morocco last Wednesday but they appeared determined to set that right against the Asian powerhouse.
They dominated possession, playing almost three times the number of passes than their Asian opponents, and were more intent on creating chances through the midfield rather than just directing long balls towards Ronaldo.
Watch: Match Highlights from Fifa