The Atlas Lions might have won by a greater margin without some heroics from Comoros goalkeeper Salim Ben Boina, who notably saved Youssef En-Nesyri's late penalty.
Morocco, whose only AFCON title dates back to 1976, had already beaten Ghana 1-0 in their opening game at the tournament and are now certain to advance to the knockout stages from Group C.
Vahid Halilhodzic's team went in front in the 16th minute when the Belgian-born Standard Liege midfielder Amallah scored after the Comoros defence struggled to clear their lines following a low cross into the box by Achraf Hakimi.
Morocco could have doubled their lead before the break but centre-back Nayef Aguerd saw a header from a corner crash back down off the underside of the crossbar.
Boina, who plays in the French lower leagues, then excelled in the second half, saving from a Hakimi free-kick and then producing a remarkable quadruple save on his line, with Adam Masina denied twice in the same move.
The goalkeeper gave away a penalty for crashing into substitute Aboukhlal but redeemed himself by saving En-Nesyri's spot-kick with seven minutes left.
However, Morocco sealed the win in the 89th minute when the Dutch-born Aboukhlal, of AZ Alkmaar, slotted in after being set up by Amallah.
The Comoros, the island nation in the Indian Ocean, are still looking for their first goal and point at their first ever Cup of Nations after losing 1-0 to Gabon in their opening match.
Gabon and Ghana meet in the other Group C game later.
Highlights Morocco AFCON 2021