Aziz Bouhaddouz headed an own goal in the fifth minute of stoppage time to give Iran a stunning 1-0 victory over Morocco in the first Group B game of the World Cup.
The rank outsiders in a group also containing Spain and Portugal were set for a 0-0 draw of little use to either until Ehsan Hajsafi curled in a free kick from the left wing which Bouhaddouz tried to intercept at the near-post but instead steered it into the goal.
It was heart-breaking for Morocco, making their first finals appearance for 20 years, but after starting brightly they will rue their cautious second-half display.
Morocco keeper Munir Mohamedi had earlier made a smart double save to deny Sardar Azmoun's sharp shot and Alireza Jahanbakhsh's looping follow-up while Iran keeper Alireza Beiranvand also had to stay alert when he went full-length to touch away Hakim Ziyech's low volley.
The Iranians, who had not won a World Cup game since their victory over the United States in 1998, celebrated as if they had won the tournament but they now have a chance in a group where they must now face favourites Spain and Portugal.
We need your consent to load this rte-player contentWe use rte-player to manage extra content that can set cookies on your device and collect data about your activity. Please review their details and accept them to load the content.Manage Preferences
Morocco, who enjoyed more possession throughout, began in aggressive fashion, taking the game to their opponents and overloading their right flank as they targeted Hajsafi.
That approach almost paid off when Nordin Amrabat whipped in a dangerous cross from the right but Younes Belhandas header from an acute angle flashed wide.
Iran were missing the calming influence of suspended holding midfielder Saeid Ezatolahi as Morocco over-ran them in the centre of the park with the clever Mbark Boussoufa directing play as the African side frequently attacked in numbers.
Morocco almost turned that initial pressure into a goal in the 19th minute when following a scramble in the area, Medhi Benatias shot was well saved by Iran keeper Alireza Beiranvand.
Irans Portuguese coach Carlos Quieroz had clearly given his side instructions to defend deep and look to break on the counter-attack and two minutes before the break that approach almost bore fruit.
Striker Sardar Azmoun broke clear though the middle but he shot straight at Mohamedi who got up quickly to keep out a follow-up effort from Alireza Jahanbakhsh.
Chances were at a premium after the break but a well-struck effort from Morocco's Hakim Ziyech brought out a fine save from Beiranvand nine minutes from the end.
You can follow the FIFA World Cup all the way with RTÉ. Live blogs of every game on RTÉ.ie and the News Now App, with 56 games live on RTÉ television and all 64 games available on the RTÉ Player.