On a dramatic final day of qualifying, Togo scored five goals, DR Congo and Tunisia four each and Burkina Faso won with a goal nine minutes into stoppage time.
But no celebrations could match those of Uganda, whose last of five appearances at the African football showpiece was in 1978, when they finished runners-up to hosts Ghana.
Tunisia won Group A by trouncing Liberia 4-1 in Monastir with a Wahbi Khazri goal after only five minutes setting the tone.
Liberian Mark Paye cut the deficit to 2-1 on 71 minutes only for the Carthage Eagles to respond with two more goals in the following six minutes.
The Togolese shared second place in the runners-up standings with Benin and Ethiopia, but had a vastly superior goal difference.
Komlan Agbegniadan rounded off the rout with two goals in the final four minutes for the Sparrowhawks, who are coached by veteran Frenchman Claude Le Roy.
DR Congo took control in the second half to whip Central African Republic 4-1 in a top-of-the-table Group B clash and finish five points clear.
Jonathan Bolingi and Jordan Botaka scored during the final quarter after the visitors had pulled one goal back through Eloge Enza-Yamissi to trail 2-1 on 62 minutes in Kinshasa.
The last-gasp victory gave the Stallions top place in Group D on the head-to-head rule over Uganda, who qualified as the best runners-up.
Teenager Farouk Miya scored 35 minutes into the first half to give Uganda a 1-0 win over the Comoros in front of a capacity 45,000 Kampala crowd.
But the dominant Cranes wasted several chances to extend the lead and ease visible tension on the pitch and in the packed stands.
Equatorial Guinea, 2015 Cup of Nations hosts and semi-finalists, scored four goals within 16 minutes to crush South Sudan 4-0 in a Group C match in Malabo that had only pride at stake.
In five previous qualifiers against Benin, South Sudan and Mali, the Equatoguineans managed to score just twice in 450 minutes.