Iran scored twice after the eighth minute of stoppage time to snatch a stunning 2-0 win over Wales that breathed new life into their World Cup campaign and left their opponents flat on their backs and facing a make-or-break decider against England.
After Wales keeper Wayne Hennessey was sent off in the 87th minute, Iran produced a remarkable finale, with Roozbeh Cheshmi driving home to give them the lead before Ramin Rezaeian added another in the 11th minute of stoppage time.
Iran, who had been facing elimination if they lost, were almost unrecognisable from the side that was thrashed 6-2 by England in their opener, and they were deserved winners even if they left it very late.
Carlos Queiroz's side were twice denied by the woodwork in the second half at Ahmad bin Ali Stadium and made the most of the extra man after Hennessey was given his marching orders following a dreadful head-high challenge on Mehdi Taremi.
The win moves Iran to three points in Group B, two more than Wales, who were held to a 1-1 draw by the United States in their opener, with England and the U.S. facing each other later on Friday.
The group comes to a head next Tuesday, when Wales play their old rivals and Iran face the U.S.
After a tight first half the match sprang to life after the break.
The second half began with the most extraordinary treble miss as Sardar Azmoun raced through only to strike the post, Ali Gholizadeh curled the follow-up against the other post, and Azmoun headed that rebound straight at Wales keeper Hennessey.
Hennessey rode to Wales's rescue again in the 70th minute, tipping Saeid Ezatolahi's low shot from distance around the post with his fingertips, but he was then given his marching orders to set up a frantic finale.
Hennessey had raced out of his area but was beaten to the ball by Taremi, with the keeper following through and catching him square in the face with his knee.
The referee initially produced a yellow card, but a trip to the VAR monitor swiftly followed and the resulting red card felt inevitable.
The goals then arrived extraordinarily late with Cheshmi hammering home a thunderbolt of a shot in a gut punch for Wales, before Rezaeian lifted the ball delicately over the keeper to finish off Rob Page's side.
FIFA WC PIX: Rainbow bucket hats, flags allowed
Security escort fans wearing pro-Iran protest shirt
What's This Dhoni Fan Doing In Doha?
Why Brazil took nine forwards to the World Cup...