After creating little and enjoying just 32 per cent possession, Iran got their lucky break with almost the last kick when Bouhaddouz put an unstoppable near-post header past his own goalkeeper when attempting to defend a free-kick.
Morocco, who looked dangerous in parts but were toothless in attack, will be wondering how they lost a game they controlled for large periods.
Both Morocco and Iran impressed in qualifying with Morocco only conceding one goal in their eight games, while Iran remained unbeaten and only let in five goals in their 18 qualifying matches.
However, they were both left rueing the draw that saw them placed in the same group as 2010 winners Spain and European champions Portugal, with only the top two sides advancing to the last 16.
Going into injury time in St Petersburg, it looked like being a result neither Morocco or Iran wanted, before Morocco’s Sofyan Amrabat conceded a needless free-kick by fouling Saman Ghoddos near the corner flag.
But that gave Ehsan Haji Safi the opportunity to whip in the free-kick, and Bouhaddouz could only steer the ball into his own net for an unlikely Iran victory.
Morocco will now need a positive result when they play Portugal on Wednesday, 20 June (13:00 NGN), before Iran play Spain at 19:00 NGN on the same day.