But Nayef Aguerd’s own-goal just before halftime made it 2-1 and lifted Canada enough for them to put pressure on Morocco in search of an equalising goal for most of the second half.
Canada came agonisingly close when a header from captain Atiba Hutchinson, who came on as a second-half substitute, bounced off the crossbar and onto the goal-line.
Canada, which will co-host the next World Cup in 2026 with the United States and Mexico, had already been eliminated before the Morocco game. It ultimately lost all three of its games in Qatar, matching its three defeats at its only other World Cup appearance in 1986.
The Moroccan squad players were already jumping up and down in a huddle near the dugout well before the final whistle and coach Walid Regragui was smiling broadly and gesturing with his arms for them to keep celebrating.
Morocco has swept aside doubts that appointing Regragui less than three months before the World Cup would undermine its chances of reaching the last 16.
Morocco began its Qatar campaign with a morale-boosting draw against Croatia and then beat Belgium 2-0 for arguably its best result in international soccer.
Morocco has now won as many games at this World Cup as in all of its previous appearances at the tournament combined and is on course for its best performance at the tournament. The North African country’s only major international soccer title came at the 1976 African Cup of Nations.
A bad Canadian error gifted Morocco the opening goal at Al Thumama Stadium when Steven Vitoria’s back pass put goalkeeper Borjan under pressure.
But instead of clearing downfield, Borjan inexplicably side-footed the ball gently in the direction of Ziyech, who chipped it first-time back over Borjan and into the unguarded goal.
For the second goal, Achraf Hakimi’s long ball dropped between Canada defenders Vitoria and Kamal Miller, and En-Nesyri chased it down and fired past Borjan to put Morocco in control.
Canada got one back when Sam Adekugbe’s cross deflected off the right foot of Aguerd and in via another touch off goalkeeper Yassine Bounou’s right glove.
Bounou was back in goal for Morocco after missing the Belgium win when he fell ill minutes before kickoff and had to be replaced.
Canada came within a whisker of avoiding defeat for the first time in its six World Cup matches when Hutchinson rose over the defenders around him at a corner and headed goalward.
The ball crashed into the underside of the crossbar, bounced down on the line and Alistair Johnston couldn’t force in a follow-up header.
Replays showed part of the ball had crossed the line but not all of it.