Morocco outplayed Canada to secure the top spot of Group F, as they reach the World Cup knockout stage for the first time in 36 years.
The Atlas Lions, whose previous trip to the last 16 came in 1986, finished above 2018 finalists Croatia, while Belgium – ranked second in the world – is out after finishing third in the group.
A tough test awaits in the next round against the team that finishes second in Group E, which could potentially be Spain or Germany.
Morocco went ahead after just four minutes courtesy of a goalkeeping howler from Milan Borjan.
The Canada keeper sprinted out of his goal but passed the ball straight to Ziyech, who lofted a cool finish into an open net from 30 yards.
The north African side doubled their advantage through Youssef En-Nesyri’s well-articulated goal as he controlled Achraf Hakimi’s superb pass before firing in.
The sloppy defending gave Canada a route back into the game when West Ham’s Nayef Aguerd stuck a boot out to divert the ball into his net – the 100th goal scored at this World Cup.
If they avoided defeat they would go through, Morocco were happy to sit back and soak up pressure in the second period.
But Atiba Hutchinson also scored with a header that rattled the crossbar and dropped down onto the line as Canada’s campaign ended without a point.