Holders Egypt qualified with a 1-0 win against Botswana in Cairo concluding their laboured campaign.
Mali were 2-0 winners against Togo in Lome and finish top of the group. Riots broke out at the Kegue Stadium, with Togo fans angry at the defeat.
Benin beat Sierra Leone in Freetown by the same scoreline, and qualify as one of the three best runners-up.
The results dashed the hopes of Uganda, who finished second in Group Three with 11 points, the same tally as Benin. But the Squirrels had the better goal difference, and will make their second appearance at the Nations Cup finals next January.
The Pharoahs played well against Botswana and should have won by a much bigger margin, but were wasteful in front of goal.
With strikers Emad Moteab and Amr Zaki firing blanks, coach Hassan Shehata pulled the pair off and replaced them with two midfielders.
The goal was to come from one of the substitutes, as Ismaili midfielder Mohamed Sadle headed home in the 76th minute.
Needing a win to qualify, the Zebras defended for much of the match but did produce some useful counter-attacks.
In Lome, Freddi Kanoute put Mali ahead towards the end of the first half, converting a cross from Bassala Toure. Mamadou Diallo sealed the victory in second-half stoppage-time, in a game that Togo had to win if they were to qualify.
Some Togo supporters threw objects onto the pitch after the second goal, and some spectators were injured and taken to hospital.