Rouzbeh Cheshmi scored in the eighth minute of stoppage time to end a tense stalemate with Wales and put Iran on course for a 2-0 World Cup victory.
Cheshmi's strike from outside the box was just beyond the diving reach of Wales substitute goalkeeper Danny Ward, who was pressed into duty when Wayne Hennessey was sent off in the 86th minute of Friday's Group B clash.
Ramin Rezaeian added a second goal after a quick counter-attack in the dying seconds. Iran celebrated wildly while some of the Welsh players dropped in disbelief to the field.
The game was still in the balance when Hennessy was shown a red card, after a VAR check, in the 86th minute for a high challenge on Mehdi Taremi outside his penalty area.
Hennessy became the first player to be sent off at Qatar 2022, and only the third goalkeeper in the history of World Cup final tournaments.
Gareth Bale made a record 110th appearance for Wales, but the Welsh appeared sluggish.
They might have fallen behind earlier when Iran hit both posts in the space of a few seconds in the second half.
First Sardar Azmoun raced clear, only to shoot against the right-hand post, then Ali Gholizadeh curled the follow-up against the other post.
Finally, Azmoun headed that rebound straight at Hennessey.
Iran also had a goal chalked off in the first half for offside against Ali Gholizadeh after a slick passing move.
Wales' best efforts were an early volley from striker Kieffer Moore, straight at the goalkeeper, and a rising shot from defender Ben Davies, tipped over by Hossein Hosseini.
Wales were making their first appearance at a World Cup since 1958 and Bale admitted he was "gutted" by the defeat.
Wales must now defeat England on Tuesday to have any hope of progressing.
"It's gutting, we're gutted, there's no other way to say it," Bale said.
"We fought to the last seconds but it's difficult to take. But we have to pick ourselves up straight away, it's going to be difficult but we have one game left."
Wales manager Rob Page said: "Our performance before the red card was not acceptable.
"We hoped it would all come together today, but we were nowhere near the levels we've set and the standards we've set in recent games.
"One or two you can carry, but when there are so many off days there is only one outcome.
"I always take responsibility, that's my team. The sending off didn't help, of course, but at that point we had five forwards on the pitch so couldn't get a defensive shape."
Iran's coach, Carlos Queiroz, said: "A wonderful day for us. This is just the beginning, but we need to finish the job. All respect to my players, today showed they love to play football.
"Two points. We played today with amazing character, which is the profile of our team. We play with a sense of unity, cohesion. After the first game we need to get back on route."
Prior to the match Iran players sang the national anthem after remaining silent against England in an apparent protest against their regime and in support of wide-ranging protests at home. However, a large number of their fans appeared to boo it.
Before the match there were reports of clashes outside the Ahmad bin Ali Stadium, with pro-government fans harassing anti-government national team supporters.
However, the joy for Iran and their noisy supporters inside the stadium was unconfined when they scored their two late goals.