The draw took place in a glamorous location next to the Sphinx and pyramids in Giza
Hosts Egypt will face DR Congo, Uganda and Zimbabwe in Group A at the 2019 Africa Cup of Nations.
Defending champions Cameroon are in Group F with Ghana, Benin and Guinea-Bissau.
The tournament will take place from 21 June to 19 July, meaning Europe-based players will not miss club games.
It is the biggest Afcon yet, with 24 teams, and the first to be held in Europe's summer rather than January or February.
The draw was held next to the pyramids of Giza.
Morocco coach Herve Renard is looking to win an unprecedented third Africa Cup of Nations - with a third team. The Atlas Lions are in Group D with one of the previous teams he won it with, the Ivory Coast. South Africa and neighbouring Namibia complete that group.
The first game of the tournament will be Egypt - who are likely to have Liverpool star Mohamed Salah in their team - against Zimbabwe on 21 June at Cairo Stadium.
Two of the three tournament debutants - Madagascar and Burundi - are in Group B with Nigeria and Guinea.
The other new team, Mauritania, are in Group E with Tunisia, Mali and Angola.
Senegal and Algeria are alongside Kenya and Tanzania, who have only qualified once before - in 1980 - in Group C.
Two teams from each group will go into the last 16, with the four best third-placed teams also progressing.
Draw in full
Group A: Egypt, DR Congo, Uganda, Zimbabwe
Group B: Nigeria, Guinea, Madagascar, Burundi
Group C: Senegal, Algeria, Kenya, Tanzania
Group D: Morocco, Ivory Coast, South Africa, Namibia
Group E: Tunisia, Mali, Mauritania, Angola
Group F: Cameroon, Ghana, Benin, Guinea-Bissau
-- Courtesy of BBC Sport