Belgium would have become the second team after defending champion France to qualify for the knockout stage if it had beaten the Moroccans but now will play 2018 finalist Croatia in what will be a crucial final group game.
Morocco, which thrived off the deafening support provided by its fans at Al Thumama Stadium, also had a goal from a free kick by Ziyech disallowed in the first half for offside.
Belgium coach Roberto Martinez put in forward Romelu Lukaku, the country’s record scorer, as a substitute with less than 10 minutes to go in a desperate attempt to get one back when it was 1-0.
Lukaku hadn’t played since October and is only just returning from a left thigh problem.
Belgium reached the semifinals at the 2018 World Cup in Russia, driven by goals from Lukaku, De Bruyne and Eden Hazard, but lost to eventual champion France. The Belgians were also impressive early at last year’s European Championship, eliminating Portugal before losing to Italy in the quarterfinals. Italy went on to win that title.
Belgium labored to a 1-0 win over Canada in its opening game in Qatar, when the absence of Lukaku was glaring. Belgium again dearly missed the big striker, who scored four goals at the 2018 World Cup and another four at Euro 2020.
Morocco drew confidence from a 0-0 draw with Croatia in its first game and boosted its chances of reaching the knockout round for first time since 1986 — the only time it has ever advanced.