Roozbeh Cheshmi and Ramin Rezaeian scored in the 98th minute and 101th minute respectively to hand Carlos Queiroz's Iran a real chance of qualifying for their first World Cup knockout stages, leaving Wales with it all to do to make the next round.
Rob Page's Wales struggled to find any rhythm throughout the game and they faced an uphill task when Wayne Hennessey was sent off late on, before Iran made them pay. Iran have three points after two games ahead of their clash against United States next week, while Wales remain on one point.
England will effectively qualify from Group B with a draw against the U.S. later on Friday, and will effectively win the group if they beat Gregg Berhalter's men.
"We are gutted, there is no other way to say it," Wales captain Gareth Bale told the BBC after the match. "We fought until the last second and we need to go again.
"We are all gutted but we have to pick ourselves up straight away. It is going to be difficult for us for sure. We will have to see."
There were off-field incidents before the game as Iranian pro-government fans harassed anti-government supporters outside the stadium. In contrast to their stance against England, the Iranian players decided to sing the national anthem amid loud jeering from the Iran fans in the ground.
Less than five minutes later, Iran had the ball in the back of the net through Ali Gholizadeh but VAR ruled out the effort for offside. The match ended goalless at half time, which has now happened in the last five matches at the World Cup.
Iran, who lost 6-2 to England in their opening match, were the better side after the break, and struck the woodwork twice in a matter of seconds. Sardar Azmoun was put through on goal but his effort hit the post. The ball then fell to Gholizadeh and his curling shot struck the other post before Hennessey stopped Azmoun's rebound.
Hennessey was called into action once again after 73 minutes as he produced an excellent save to deny Saeid Ezatolahi.
However, his game ended prematurely after he was shown a red card for a high challenge on Mehdi Taremi with five minutes remaining. The goalkeeper was initially shown a yellow card but the referee overturned his decision after a VAR check.
Iran sparked scenes of jubilation with their goal in the 98th minute, when Cheshmi struck a stunning strike from the edge of the box. Rezaeian then wrapped up the points after a quick counter attack to clip the ball over substitute goalkeeper Danny Ward.
"This is just the beginning, but we need to finish the job," Iran head coach Quieroz told the BBC. A wonderful day for us. All respect to my players, today showed they love to play football.
"Our players deserve to be supported. We want to play for the fans."