Iran were eliminated from the World Cup despite scoring a late penalty to bring them level with Portugal.
Quaresma scored a stunning effort on the stroke of half-time to give Portugal the lead. Ansarifard came off the bench for Iran to score from the same spot and give the side hope in a physical match.
Cristiano Ronaldo spurned the chance to go level with Kane as World Cup top scorer when Beiranvand saved his spot-kick, awarded by VAR following a foul by Eztolahi.
Both Haji Safi and Azmoun were booked for their protests, as the game flared up with a number of reckless challenges from both sides.
Iran were awarded penalty late on and Ansarifard coolly dispatched it. This very nearly turned the game on its head but Mehdi Taremi hit the side netting.
Five takeaways from Iran vs Portugal
No love lost
There was no love lost between former Portugal manager Carlos Queiroz and his former team — he was asking for VAR on some key decisions and received a number dressings down from the referee.
Ronaldo's bad day
Four goals in the previous group stage games gave Ronaldo the perfect platform to equal Harry Kane for the Golden Boot but, instead, he missed a penalty and was subject to a VAR decision over a possible red card.
VAR takes centre stage
This game will be marred by the number of decisions that went down to VAR. Two penalties were awarded by it, as well as a subjective decision concerning Cristiano Ronaldo for a red card.
Portugal need to focus
Conceding a late penalty and then very nearly being eliminated from the competition, this Portuguese defence will need to shape up against a better-attacking opposition in the form of Uruguay.
Iran well drilled
Other than a setback from Quaresma, the Iranian defence were well organised and frustrated the opposition a number of times. If Iran had been more clinical in the final third, their name would be in the knockout stages of the World Cup.