It looked as though neither side would make the most of the chance to start with a victory, only for Aziz Bouhaddouz to head past his own goalkeeper at the near-post in the dying stages to hand Iran a 1-0 win.
It is just their second ever World Cup win and came two decades after a 2-1 success against the United States at France 98.
Morocco will rue their chances after being the better side for the majority of the game, dictating an electric pace to the opening stages and looking to release Ayoub El Kaabi over the top whenever possible, leaving Herve Renard's side as great outsiders to qualify ahead of Spain and Portugal.
OWN GOAL! The free-kick is delivered in out wide and Morocco substitute Bouhaddouz's desperate attempt to keep the ball out ends up in his own net pic.twitter.com/IvBJ0ez7uZ
Morocco have never won their opening match at a World Cup tournament (D2 L3), also failing to win in 1970, 1986, 1994 and 1998.
Iran won just their second match at the World Cup (D3 L8), with this their first since beating USA in June 1998.
Iran did not attempt a single shot in the second half and were the first team since 1966 to score a goal in a half of World Cup football without attempting a shot.
Iran kept only their second World Cup clean sheet – their other came in a goalless draw with Nigeria in June 2014.
Carlos Queiroz has never lost against an African nation in the World Cup (W1 D2), keeping three clean sheets in those matches.