Sudan forced Morocco to a frustrating 0-0 draw in the final Group A match at the Stade Mohamed V in Casablanca on Sunday.
The draw however, did not stop the Atlas Lions from finishing top of the Group with a better goal difference while Sudan also advanced to the quarters as the runners-up.
Achraf Bencharki had his second-half penalty saved and, despite dominating, the hosts could not find a way past Akram El Hadi Salim in the Sudan goal.
In another Group A match, Guinea salvaged some pride with a 1-0 over Mauritania. The only goal was scored by captain Ibrahima Sory Sankhon after 15 minutes.
Against Sudan, the Atlas Lions made their intentions clear when Walid El Karti forced Sudan goalkeeper Akram Salim into a good save just seven minutes into the game.
Morocco, who made 10 changes from their win over Guinea, created chances right from the start of their top-of-the-table decider against Sudan, with Bencharki lifting the ball just over after only two minutes.
The Moroccans should have taken the lead in the 48th minute when Walid El Karti was fouled in the area by Bakri Bachir but Akram guessed the right way and pushed aside Bencharki's spot-kick.
Akram also made a good save from a Jawad El Yamiq header after 73 minutes, while Ayoub El Kaabi fired a shot just wide of the post as he looked to score his sixth goal of the tournament.
Morocco were awarded a penalty after El Karti was fouled by Sudan defender Bakri Bashir in the box four minutes after the restart. Achraf Bencharki stepped up but he was denied by Sudan's towering keeper Salim, who guessed the right way and thwarted the Moroccan attacker's effort.
Morocco and Sudan must wait to see how Group B finishes to find out, who they face in Saturday's quarter-finals. Namibia and Zambia play each other on Monday to decide the winner of that pool.
Sudan: Salim, Hassan, Abdalla, Ibrahim, Mohammad, B.Bashir, El Tahir, M.Bashir (Eldin 62'), Idris (Taher 60'), Gismalla, Bakhit (Elnour 82').
Morocco: M'Hamdi, El Hachimi, Aguerd, Semmoumy, Hammoudan (Hadraf 72'), El Karti (El Hadded 83'), Boulhroud, El Yamiq, Yabrane, Nanah (El Kaabi 71'), Bencharki.