(CNN) Two late goals secured Iran a sensational 2-0 win against Wales to maintain its hopes of qualifying for the World Cup knockout stages.
Rouzbeh Cheshmi struck from distance to brilliantly give Iran the lead in the 98th minute, while Ramin Rezaeian sealed the win in the 101st minute, securing Iran its first points of the tournament.
Both goals came after Wales goalkeeper Wayne Hennessey had been sent off in the second half for a rash challenge outside his area, becoming the first player in this tournament to be shown a red card.
Iran created the better chances and was a deserved winner in a match filled with tension as both teams needed victories to boost their chances of progressing from Group B.
Iran's players joined in the singing of the national anthem ahead of Friday's match, while at the same time, boos could be heard inside the Ahmed bin Ali Stadium in Qatar.
During the playing of the national anthems before Iran's opening match against England on Monday, the Iranian players stood silent in what was widely interpreted as a show of solidarity with those protesting back home.
Iran is appearing at this World Cup under the shadow of domestic turmoil, with this game taking place a day after the United Nations High Commissioner for Human Rights Chief, Volker Turk, said that the country is in a "full-fledged human rights crisis" as authorities clamp down on anti-regime dissidents.
Protests, referred to by experts as the most significant since the establishment of clerical rule following the 1979 Iranian Revolution, and violence have rocked Iran in recent months and threatened the very nature of the country's regime, which has been in power for more than 40 years.
It was sparked by the death of Mahsa Amini, a 22-year-old woman who died after being detained by Iran's morality police, allegedly for not abiding by the country's conservative dress code. Iranian security forces have unleashed a violent response.
After the heavy 6-2 defeat by England, Iran played much better in its second match.
The score was goalless at the break after a nervy opening 45 minutes on a sweltering day in Al Rayyan. Wales striker Kieffer Moore had the best chance of the half, somehow heading wide when free on goal.
Though Ali Gholizadeh thought he had put Iran ahead, the video assistant referee (VAR) ruled out the goal for offside.
Iran star Sardar Azmoun twice hit the post early in the second half as Iran set the tempo and Wales rode its luck, and it looked as if both teams would share a point each before Cheshmi opened the scoring -- sending Iranian fans into celebrations and muting the Welsh contingent.
Elsewhere, World Cup host Qatar is out of the tournament after a second successive loss, losing 3-1 to Senegal.
The Maroon became the first host nation in World Cup history to be knocked out after only two games.
Qatari fans will be disappointed with a mediocre performance from a team that has been 12 years in the making and came into the tournament as Asian champions.
Qatar was much improved from its opening day loss to Ecuador, but it was overpowered by a Senegal team that finally arrived at the World Cup. Senegal's victory was the first time an African team had won at Qatar 2022.
The Netherlands and Ecuador sealed Qatar's fate when they played out an entertaining 1-1 draw.
The Dutch raced into a lead, scoring the quickest goal of the tournament from new star Cody Gakpo's stellar strike.
But the Oranje were unable to control the game as the young Ecuador team fought its way back into the game, grabbing a deserved equalizer early in the second half through talisman Enner Valencia.
The Maroon became the first host nation in World Cup history to be knocked out after only two games.