Wales' first World Cup for 64 years looks set to end at the first hurdle after a gut-wrenching - but deserved - last-ditch defeat by Iran in Qatar.
Substitute Roozbeh Cheshmi struck from 20 yards nine minutes into stoppage time, before Ramin Rezaeian finished off a counter-attack to seal victory for a revitalised Iran side, who have renewed hope of reaching the knockout stages for the first time in their history.
Those were decisive blows to Welsh prospects of victory, which had all but vanished when goalkeeper Wayne Hennessey was sent off with four minutes of normal time remaining, following a video assistant referee check, for a reckless challenge on Medhi Taremi.
As they did in their opening draw with the United States, Wales started poorly and had the video assistant referee (VAR) to thank for disallowing a goal from Iran's Ali Gholizadeh for offside.
In one of the most highly charged atmospheres of this World Cup, Iran's players sang their national anthem this time - having declined to do so before their opening loss to England in an apparent show of support for anti-government protests in their country - but their own fans booed the anthem and some could be seen crying in the stands.
Roared on by the fervent and almost entirely Iranian crowd, Carlos Queiroz's side were extremely unlucky not to score early in the second half as Sardar Azmoun and Gholizadeh both struck the post within the space of a few seconds.
Wales were utterly ragged and, as they pushed forward in search of the late winning goal they desperately needed, a long ball over the top left the defence exposed and the onrushing Hennessey brought down Taremi.
Hennessey was initially shown a yellow card, but it was changed to a red after the referee was advised to check on the pitchside monitor, with the 35-year-old becoming only the third keeper to be sent off at a World Cup.
That set the seal on Wales' fate for this match and, in all likelihood, their hopes of reaching the second round.
While Robert Page's men were just as disjointed as they were against the USA, Iran were unrecognisable from the team thrashed 6-2 by England in their first match and fully deserved this win.
Wales now face the formidable challenge of needing to win their final group match on Tuesday against England, who take on the United States later on Friday.
It is not impossible but, based on how the Group B teams have fared so far in Qatar, Wales' first World Cup for 64 years looks like it is in serious danger of ending at the earliest stage.
Wales rue another sloppy performance
Having been absent from World Cups since 1958, Wales marked their emotional and long-awaited return to football's grandest stage with a 1-1 draw against the United States at the same stadium on Monday.
They seemed overawed by the magnitude of that occasion during a first half in which they were overrun and outplayed by the USA, but were much improved after the half-time introduction of Kieffer Moore.
The Bournemouth striker started this time and, while his presence gave Wales an added dimension in attack, they were still as worryingly porous in midfield, as they had been against the US.
Iran sensed that weakness and pressed their opponents high up the pitch, prompting panic among Wales' midfielders and defenders, particularly on the break.
Despite their vulnerability through the middle, where Page had stuck with the same selection, Wales looked more dangerous when they played with width, and it was Moore who stood to benefit.
Connor Roberts found the 6ft 5in forward with a fine cross from the right in the 13th minute and, although Moore stretched to connect with a volley, it was straight at goalkeeper Hossein Hosseini.
Roberts' next involvement three minutes later was less distinguished, as his cross-field pass was cut out near his own penalty area, allowing Sardar Azmoun to tee up Gholizadeh, who finished into an empty net. There was no flag at first but, after a swift VAR check, the goal was disallowed for offside.
Azmoun headed the next chance over as Wales struggled to get a hold of the game. Fortunately for them, as energetic and well-drilled as Iran were, they did not create much in the way of genuine scoring opportunities.
Wales slow to make changes
Despite the clear issues his side faced in the first half, Page made no changes at half-time.
Just as his inability to heed the lessons from the USA game invited Iranian pressure in the first half, Page's inaction on this occasion forced Wales on to the back foot during the second half.
They were extremely fortunate not to fall behind five minutes after the restart when Iran hit the post twice in the space of a few seconds.
First, Azmoun struck a right-footed effort which cannoned off the woodwork and fell to Gholizadeh, whose curling left-footed shot hit the other post. Azmoun was the first to react, but his rebound was smothered by Hennessey.
Wales were a mess at this point, their defence harassed and given next to no protection from the players in front of them.
Those struggles made it impossible to attack with any cohesion, rendering Gareth Bale and Aaron Ramsey almost obsolete.
It was a dispiriting sight for Wales fans to watch these two greats - heroes of the past two European Championships - reduced to peripheral figures on this occasion.
Wales still threw themselves forward in the vague hope of forcing a late winner, but that desperation was their undoing when Hennessey caught Taremi with a high boot.
The day belonged to Iran, who left it late to secure the victory they richly deserved.
Given too much time by Wales' tiring bodies, Cheshmi unleasehd a superb strike from 20 yards which whistled into the bottom corner to prompt wild celebrations. It was the World Cup's 42nd goal, but the first from outside the box.
Then with Wales even more exposed, it was left to Rezaeian to apply a delicate finishing touch as Iran surged to victory, knowing another against the USA will secure their passage to the second round for the first time.Wales players sink to the turf after Iran's opening goal
Player of the match
11Bale13Moore1HennesseyBooked at 86mins5Mepham6RodonBooked at 45mins4Davies14RobertsSubstituted forJohnsonat 57'minutes10RamseySubstituted forWardat 87'minutes15AmpaduSubstituted forAllenat 77'minutes8WilsonSubstituted forJamesat 58'minutes3N Williams11Bale13Moore
20Azmoun24Hosseini23RezaeianBooked at 90mins19Hosseini8Pouraliganji5Mohammadi17GholizadehSubstituted forJahanbakhshat 77'minutesBooked at 90mins6EzatolahiSubstituted forKarimiat 83'minutes21NoorollahiSubstituted forCheshmiat 78'minutes3HajisafiSubstituted forTorabiat 77'minutes9Taremi20AzmounSubstituted forAnsarifardat 68'minutes
Match ends, Wales 0, IR Iran 2.
Second Half ends, Wales 0, IR Iran 2.
Goal! Wales 0, IR Iran 2. Ramin Rezaeian (IR Iran) right footed shot from the centre of the box to the centre of the goal. Assisted by Mehdi Taremi following a fast break.
Goal! Wales 0, IR Iran 1. Roozbeh Cheshmi (IR Iran) right footed shot from outside the box to the bottom right corner.
Attempt blocked. Alireza Jahanbakhsh (IR Iran) right footed shot from outside the box is blocked. Assisted by Morteza Pouraliganji.
Attempt blocked. Alireza Jahanbakhsh (IR Iran) right footed shot from outside the box is blocked. Assisted by Mehdi Torabi.
Attempt blocked. Ramin Rezaeian (IR Iran) right footed shot from outside the box is blocked. Assisted by Mehdi Taremi.
Attempt missed. Brennan Johnson (Wales) right footed shot from a difficult angle on the right is close, but misses to the right. Assisted by Neco Williams.
Attempt missed. Neco Williams (Wales) right footed shot from outside the box misses to the right.
Alireza Jahanbakhsh (IR Iran) is shown the yellow card for a bad foul.
Chris Mepham (Wales) wins a free kick in the defensive half.
Foul by Alireza Jahanbakhsh (IR Iran).
Ramin Rezaeian (IR Iran) is shown the yellow card.
Dan James (Wales) wins a free kick on the left wing.
Foul by Ali Karimi (IR Iran).
Offside, IR Iran. Alireza Jahanbakhsh tries a through ball, but Karim Ansarifard is caught offside.
Kieffer Moore (Wales) wins a free kick in the defensive half.
Foul by Majid Hosseini (IR Iran).
Attempt missed. Mehdi Torabi (IR Iran) right footed shot from outside the box is high and wide to the right. Assisted by Karim Ansarifard.
Attempt missed. Karim Ansarifard (IR Iran) right footed shot from outside the box misses to the left. Assisted by Mehdi Taremi.
Get the latest results and goal notifications for any team at the Fifa World Cup by downloading the BBC Sport app: Appleexternal-link - Androidexternal-link - Amazonexternal-link
Get your daily dose of Fifa World Cup reaction, debate & analysis with World Cup Daily on BBC Sounds