DOHA, Qatar (AP) -- Walid Regragui stood in the middle of a team huddle as his players reached out and patted him vigorously on the head. Then they threw their coach in the air, almost as if they had already won the World Cup.
Regragui has been an international coach for only three months but still guided Morocco to the last 16 of the World Cup for only the second time in its history with a 2-1 win over Canada on Thursday. It clinched first place in Group F for Morocco, ahead of 2018 finalist Croatia and semifinalist Belgium.
Regragui's squad has now collected more victories at a single World Cup than any other Morocco team.
No one thought that was likely when the Moroccan soccer federation took a gamble on the 47-year-old Regragui in August by giving him his first job in charge of a national team. The payoff has been historic.
"About 50 or 60 years of Moroccan history. We've done it in a few weeks," Regragui said.
Morocco's two wins in Qatar, a huge surprise over Kevin de Bruyne and No. 2-ranked Belgium and then the victory over Canada at Al Thumama Stadium, is as many as the country had won in all its previous World Cup appearances put together. Morocco also drew its opener against Croatia to advance unbeaten.
"We trust in him," Morocco defender Achraf Hakimi said of Regragui. "He's done an amazing job with not much time."
The Moroccans' only previous trip past the group stage at a World Cup had come in 1986, when they also won their group, but won only one match.
Goals by Hakim Ziyech and Youssef En-Nesyri delivered the victory over Canada and ensured this team also went through.
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 equalizing goal for most of the second half.
The Canadians came agonizingly close when a header from captain Atiba Hutchinson, who came on as a second-half substitute, bounced down off the crossbar and onto the goal-line.
Replays showed part of the ball had crossed the line but not all of it.
"Two inches. Two inches form getting our first result," Canada coach John Herdman said. "This isn't Canada walking away with our heads down. We can keep our heads up."
But even when his team's total control suddenly disappeared, Regragui was happy with the fighting spirit.
"I loved the second half because that's the spirit we were looking for," he said. "First half, extraordinary. Second half, we fought."
Canada, which will co-host the next World Cup in 2026 with the United States and Mexico, had already been eliminated before facing Morocco and lost all three of its games in Qatar, matching its three defeats at its only other World Cup appearance in 1986.
Herdman was certain his team had made progress over the course of their three games, and also praised their fight after a bad early error put them behind.
Steven Vitoria's back pass put goalkeeper Milan Borjan under pressure. But instead of clearing downfield, Borjan inexplicably side-footed the ball gently in the direction of Ziyech, who chipped it over Borjan and into the unguarded goal in the fourth minute.
Regragui's head was a focus for the Moroccans at the end. They drummed their hands up and down on his shiny bald dome during their joyous celebrations in what's apparently become a tradition in the team.
"They love touching my head," Regragui said. "Maybe it brings them luck."
NEXT FOR HERDMAN
Herdman was looking forward to a rest and seeing his children more than anything else, he said, with an incredibly busy time ahead for Canadian soccer before the World Cup goes to North America in four years.
There were reasons to be "proud," Herdman said, after pushing both Belgium and Morocco in narrow losses in Qatar. Only Canada's 4-1 loss to Croatia was lopsided.
NEXT FOR MOROCCO
As Group F winner, Morocco will face Spain in the last 16. The Spanish lost to Japan 2-1 to finish second in Group E.
One more victory for Morocco will mean the country's first trip to the World Cup quarterfinals.
"Why not aim for the sky?" Regragui said. "Why not dream about lifting that trophy?"