Morocco confirmed their place at the 2019 Africa Cup of Nations on Saturday as Malawi were defeated 2-1 by already eliminated Comoros in Moroni.
The Atlas Lions defeated Cameroon 2-0 in Casablanca on Friday to move up to 10 points with one game to play.
Malawi could have only stood a chance of overhauling Herve Renard's side if they'd beaten Comoros away, but in the event, a 2-1 defeat confirms their elimination.
In-form El-Fardou Ben Mohamed opened the scoring for the host after two minutes but Patrick Phiri equalised for the Flames in the 67th minute.
However, three minutes later their AFCON hopes were all but extinguished when Nasser Chamed netted the hosts' winner.
Hakim Ziyech's double for the Atlas Lions proved decisive against the Indomitable Lions in Casablanca, where Karl Toko Ekambi was sent off for the visitors after diving to receive a second yellow card.
Cameroon qualified automatically for the 2019 AFCON as hosts, but still taking part in the qualifying campaign in Group B, with points from their matches counting for the other teams.
The Lions have eight points after five games, with Comoros on five and Malawi on four.