Burkina Faso scored nine minutes into stoppage time in Ouagadougou to edge Botswana 2-1 and top the standings on the head-to-head rule after a match in which three players were red-carded.
Burkina Faso and Uganda finished with 13 points each in the six-round mini-league, Botswana collected six and the Comoros three.
After 38 years littered with near misses to qualify for the biennial African football showpiece, some Ugandan players raised their arms and others sank to their knees as the final whistle sounded.
Dominant against a limited Comoran team, Uganda took the lead on 35 minutes through Belgium-based teenage midfielder Farouk Miya.
He had a shot parried by outstanding goalkeeper Ali Ahamada in a one-one-one situation, but got a second chance from the rebound and fired into the net from close range.
A tension-easing second goal eluded the home team, however, as they remained on top during the second half at the Mandela National Stadium.
Burkina Faso and Uganda join Algeria, Cameroon, Egypt, Ghana, Guinea-Bissau, Ivory Coast, Mali, Morocco, Senegal, Zimbabwe and hosts Gabon as qualifiers for the 2017 Cup of Nations.
The remaining three places will be filled later Sunday with Benin, Central African Republic, Democratic Republic of Congo, Ethiopia, Liberia, Togo and Tunisia the contenders.
In matches that had no impact on qualification, Congo beat Guinea-Bissau 1-0 in Brazzaville and Zambia and Kenya drew 1-1 in Ndola in Group E and Malawi beat Swaziland 1-0 in Blantyre in Group L.