Wales players sink to the turf after Iran's opening goal
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.
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.
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.
-- Courtesy of BBC Sport