Belgium have been knocked out of the World Cup at the group stage as Croatia progressed at their expense with a goalless draw in Qatar.
Morocco topped group F with seven points following their 2-1 win over Canada.
Croatia finished on five points, Belgium four and Canada none.
Roberto Martinez's side, who finished third in Russia four years ago and are ranked second in the world, have had a disappointing tournament with just one win in three matches.
They put in another lacklustre display against Croatia despite knowing a win was necessary to progress to the last 16.
Substitute Romelu Lukaku had numerous chances in the second half but failed to convert any.
Lukaku, still returning to full fitness following injury, poked an effort wide and then reacted too late when the ball hit him in front of goal in stoppage time.
Croatia, finalists in 2018, will face the winners of Group E - which is currently Spain - in the last 16.
An impassioned Moroccan team clinched a spot in the last 16 for the first time since 1986 by defeating the already-eliminated Canadians 2-1, mercilessly capitalising on their opponents blunders.
Morocco, who needed a win or a draw in their final Group F match to reach the knockout rounds, took advantage of a weak clearance by goalkeeper Milan Borjan that landed on the foot of Hakim Ziyech.
Cheered on by a boisterous crowd of Moroccan fans, midfielder Ziyech effortlessly lobbed the ball over the stranded goalkeeper to open scoring in the fourth minute.
Borjan had been placed in an unenviable position by central defender Steven Vitoria, whose weak back pass forced the goalkeeper to race Moroccan forward Youssef En-Nesyri to the ball.
En-Nesyri remained dangerous throughout the first half, doubling Morocco's lead in the 23rd minute when he ran onto a long ball from Achraf Hakimi and beat Borjan at the near post.
En-Nesyri also thumped a volley into the Canadian net during stoppage time in the first half but that goal was ruled offside.
Moroccan defender Nayef Aguerd put Canada on the scoreboard with an own goal, the first of this World Cup, by accidentally flicking a cross by Sam Adekugbe past his own goalkeeper Yassine Bounou in the 40th minute.
Canada, who are exiting their first World Cup since 1986 without a win, automatically qualify for the 2026 tournament as co-hosts along with the United States and Mexico.
-BBC/Reuters