Portugal nearly found the early breakthrough when Cristiano Ronaldo cut inside to take a shot but it was easily handled by the keeper.
After a quiet spell in the half, Saeid Ezatolahi was handed Iran’s best chance of going ahead, but after lining up for a free-kick, he blasted straight at Rui Patricio after 33 minutes.
Soaking up the pressure and gradually orchestrating their way around the game, Portugal’s resolve finally bore fruit as Ricardo Quaresma broke the deadlock with a stunning strike.
Following halftime, Portugal were handed a penalty on the consultation from the Video Assistant Referee after Ronaldo was brought down in the box.
The Real Madrid star dusted himself but failed to edge ahead of Romelu Lukaku and Harry Kane on the top scorers charts as Alireza Team Meli Beiranvand made the save.
Drama then unfolded for the Selecao, who conceded a penalty themselves after Cedric was adjudged to have handled inside the box.
Iran were level-pegging as Karim Ansarifard kept his cool to beat Patricio with a delicate finish in the top corner from 12 yards.
Seconds later, it appeared as if Carlos Queiroz’s men had found the winner but Mehdi Tafemi only struck the side-netting.
Despite the late drama, Portugal held their nerve to join Spain in the last 16, where respective meetings with Uruguay and host nation Russia awaits this weekend.