Iran claimed a 2-0 victory over 10-man Wales on Friday with two goals deep into stoppage time to keep its World Cup campaign alive.
The Iran players, who sang the national anthem before kickoff, sent their thousands of supporters at the Ahmad Bin Ali Stadium delirious as they celebrated beating a European team at a World Cup for the first time.
Wales goalkeeper Wayne Hennessey became the first player to be sent off at the Qatar tournament for clattering into Mehdi Taremi late in the game.
Iran, who had earlier twice struck the woodwork, finally broke the deadlock in the 98th minute through substitute Rouzbeh Cheshmi's powerful drive. Ramin Rezaeian clipped in a second on the counterattack three minutes later.
Iran, which would have been eliminated with a defeat, instead climbed to second in Group B behind England, which beat it, 6-2, in its opening game. Victory for Iran on Tuesday in their politically charged clash with the United States would take it into the knockout phase for the first time.
"We need the supporters to support us like always," said Mehdi Taremi. "Even those who are in Iran behind their TV, we need their positive energy and then we will win the game because we have our dream and we want to give that dream a chance."
Wales tumbled to the bottom of the group and will have to defeat England in their final match next week to have any chance of reaching the last 16 in its first World Cup since 1958.
"We're gutted. There is no other way to say it," captain Gareth Bale told the BBC. "We've fought until the last second. It's one of those things. It's difficult to take but we have to recover and go again."
The Iran players opted to sing the national anthem in contrast to their stance before the game against England, when they remained silent in an apparent gesture of solidarity with anti-government protestors. Some Iranian fans were in tears during the anthem.
Wales manager Rob Page elected to start striker Kieffer Moore, whose early volley was parried by Iran goalkeeper Hossein Hosseini.
Iran thought it had taken the lead minutes later but Ali Gholizadeh was clearly offside before he tapped in and the goal was ruled out by VAR.
A cagey game burst into life during a crazy spell shortly after halftime when Sardar Azmoun and Gholizadeh both struck the woodwork within seconds. Rejuvenated Iran suddenly looked like scoring every time they went forward and Ethan Ampadu had to make an excellent block to deny Taremi the opening goal.
Wales had Hennessey to thank for staying on level terms with 17 minutes left, as he stretched to tip Saeid Ezatolahi's low shot around the post.
The game opened up in a frantic final minutes as both sides knew it likely needed more than a draw. Iran was given a huge boost in its push for a winner when Hennessey recklessly charged out of his goal and crashed into Taremi.
Remarkably, Guatemalan referee Mario Escobar only initially booked the goalkeeper, but that was corrected after a VAR review and Hennessey was dismissed in the 86th minute.
Leicester's Danny Ward took his place and quickly saw Torabi's effort fly past his post. But an emotional day for Iran and their fans finished in dramatic fashion when Cheshmi hammered home from the edge of the box and Rezaeian raced clear to chip over Ward.
© Agence France-Presse