Morocco coach Herve Renard masterminded another victory over his former team Cote d'Ivoire on Friday as a 1-0 win sent the north Africans through to the last 16 in Egypt.
Youssef En-Nesyri's superb first-half goal in Cairo earned Renard and Morocco a third win in a row over an Ivorian side he coached to the Africa Cup of Nations title in 2015.
After ending Cote d'Ivoire's involvement at the 2017 edition and qualifying for last year's World Cup at their expense, Morocco again got the better of their west African opponents in a meeting of the top two sides in Group D.
Morocco need a point in their final game against South Africa to be assured of top spot, although Ivory Coast will likely still join them in the knockout rounds as runners-up with a match to come against underdogs Namibia.
"Our first goal is go further than we did in 2017," said Renard, whose Morocco lost to Egypt in the quarterfinals two years ago.
"We are potentially stronger now but we need to keep the same state of mind. If we reach our goal we'll see what we can do. There's still a long way to go and it's going to be a difficult competition for everyone."
Jonathan Kodjia struck the winner in Cote d'Ivoire's opening 1-0 win over South Africa and the rangy Aston Villa forward nearly struck inside the first minute, connecting with Serge Aurier's flighted cross only for Romain Saiss to brilliantly head over from under his own bar.
Morocco had toiled in the sweltering afternoon heat in their 1-0 victory over Namibia in their first game and they too went close in front of a mostly full Al Salam Stadium when En-Nesyri flashed a shot just the wrong side of the post from Nabil Dirar's smart cross.
Leganes forward En-Nesyri put Morocco ahead on 23 minutes but it was the work from Nordin Amrabat that deserved much of the credit, the former Watford winger slaloming past three Ivorian defenders before slipping a cute ball through for En-Nesyri to slot beyond Sylvain Gbohouo.
Nicolas Pepe almost brought the Ivorians level moments later as the ball fell to him on the edge of the box after Morocco goalkeeper Yassine Bounou knocked the ball away from Max Gradel, but the in-demand Lille star failed to hit the target with a pair of covering defenders.
Amrabat and En-Nesyri promptly combined once more to great effect, the former dummying intelligently to allow the forward a low strike at goal that Gbohouo saved well before falling on the rebound.
Midfielder Geoffrey Serey Die thumped just over from distance after a poor Bounou clearance asCote d'Ivoire struggled to carve out genuine openings while Younes Belhanda, back in the Morocco side after injury, forced Gbohouo to push over his curling effort.
Cote d'Ivoire substitute Wilfried Bony, without a club following his release by Swansea, planted a header wide with Ismael Traore's spectacular overhead attempt smothered comfortably by Bounou.
Noussair Mazraoui, on as a late replacement for Hakim Ziyech, volleyed against the bar in stoppage time after a clinical break as Morocco secured a win that should leave them on course to face a third-place finisher for a spot in the quarterfinals.