Morocco powered into the last 16 of the World Cup for the first time in 36 years on Thursday with a 2-1 victory over already-eliminated Canada.
Goals from Hakim Ziyech and Youssef En-Nesyri ensured the North Africans finished top of Group F ahead of 2018 World Cup runners-up Croatia.
Morocco, who last reached the knockout stages of the World Cup in 1986, will face Spain, the runners-up from Group E in the last 16.
"It wasn't easy, but when you have an opportunity to make history, you remember it," Morocco coach Walid Regragui said.
"We've made lots of people happy this evening, but let's not stop here.
"Before the tournament we set an objective – we said we wanted to give everything we've got and get out of the group stages. We can tick that box now."
Canada's defeat capped a disappointing World Cup for the CONCACAF side, who depart after losing all three of their group games on their long-awaited return to the finals.
But coach John Herdman said his team would leave Qatar with heads held high.
"It's been the first time in a long time we've been here. We'd liked to have been longer but we've enjoyed the ride," Herdman said.
Morocco put themselves firmly on course for the second round after upsetting Belgium 2-0 on Sunday, a result that left them needing only a point against Canada on Thursday to be sure of advancing.
Croatia coach Zlatko Dalic admitted his side were fortunate that Belgium missed several chances in the goalless draw on Thursday that sent the 2018 runners-up into the World Cup knockout phase.
The Croatians hung on for the point they needed to progress from Goup F behind Morocco as Belgium striker Romelu Lukaku passed up several golden opportunities to put them out late on.
"I expected a difficult match against Belgium. Belgium cannot play three bad matches in a row," Dalic said in the post-match press conference.
"We had some chances against us but it didn't change our mindset ... We were lucky they didn't take their chances."
Croatia will now face Japan, the winners of Group E for a quarter-final spot at the Al Janoub Stadium on Monday.
Belgium defender Timothy Castagne said Lukaku should not be blamed for their World Cup exit despite the striker's misses in the goalless draw that sealed their fate, said.
Lukaku, Belgium's record goalscorer, had only played a handful of minutes in the tournament due to injury before coming on at half-time at the Ahmad Bin Ali Stadium.
The striker, on loan at Inter Milan from Chelsea, missed three gilt-edged chances late on when a goal would have sent his side into the last 16.
"I wouldn't say he's the anti-hero because he's there for the chances, he also creates them, he gives, he keeps the ball," defender Castagne told reporters.
"Maybe if he's not there, we don't have those chances. I don't think we can blame him, he gave everything, he tried. If it doesn't go in, it doesn't go in."
Belgium finished third in Group F on four points after beating Canada 1-0 and losing 2-0 to Morocco.