Uganda have qualified for the Africa Cup of Nations for the first time since 1978 after beating Comoros on Sunday.
Their 1-0 victory secured their place at next year's finals in Gabon as one of the two best group runners-up.
Group D rivals Burkina Faso also qualified with a late 2-1 win over Botswana to finish top of the table.
Tunisia and DR Congo qualified as winners of their groups and Togo went through as the second best group runners-up on goal difference.
Sixteen teams will compete at next year's tournament, which runs from 14 January to 5 February: the 13 group winners and two best group runners-up, plus hosts Gabon.
Algeria, Cameroon, Egypt, Ghana, Guinea-Bissau, Ivory Coast, Mali, Morocco, Senegal and Zimbabwe had booked their places before Sunday's matches.
Burkina Faso, who lost to Nigeria in the 2013 final, left it very late to guarantee their qualification after Prejuce Nakoulma's 18th-minute opener was cancelled out by a Botswana equaliser from the penalty spot.
Visitors Botswana fought to hold their opponents, despite having Lesego Galenamotlhale dismissed on 61 minutes and Kabelo Dambe sent off with two minutes of normal time remaining.
But Banou Diawara struck deep into injury time for the Burkinabe, who had Steeve Yago sent off moments before, to give them the victory and 13 points from their six group games.
Uganda also reached 13 points, thanks to a 35th-minute winner by Farouk Miya in Kampala, but they finished in second place in the group because of a inferior head-to-head record against Burkina Faso.
However, it was enough to send the Cranes to the finals for the first time for 38 years. Some Ugandan players raised their arms and others sank to their knees at the end of the match.
Uganda's last appearance at the Nations Cup ended in a runners-up spot when they lost to Ghana in the final.
|Final round of 2017 Africa Cup of Nations qualifiers|
|Group A||Group B||Group C|
|Togo 5-0 Djibouti||Angola 1-1 Madagascar||Equatorial Guinea 4-0 South Sudan|
|Tunisia 4-1 Liberia||DR Congo 4-1 Central African Republic||Mali 5-2 Benin|
|Group D||Group E||Group F|
|Burkina Faso 2-1 Botswana||Congo 1-0 Guinea-Bissau||Cape Verde 0-1 Libya|
|Uganda 1-0 Comoros||Zambia 1-1 Kenya||Morocco 2-0 Sao Tome e Principe|
|Group G||Group H||Group I|
|Nigeria 1-0 Tanzania||Ghana 1-1 Rwanda||Ivory Coast 1-1 Sierra Leone|
|Mozambique 1-0 Mauritius||Sudan 1-2 Gabon|
|Group J||Group K||Group L|
|Ethiopia 2-1 Seychelles||Senegal 2-0 Namibia||Malawi 1-0 Swaziland|
|Algeria 6-0 Lesotho||Niger 0-0 Burundi||Guinea 1-0 Zimbabwe|
|South Africa 1-1 Mauritania||Cameroon 2-0 The Gambia||All times GMT|
Togo were, perhaps, the surprise qualifiers as other results went their way and they thrashed Djibouti 5-0 to book their place as a best group runner-up.
Vincent Bossou opened the scoring and Komlan Agbegniadan grabbed a brace in a three-minute spell at the end of the match to add further gloss to the scoreline.
The win meant Togo finished in second in Group A as Tunisia beat Liberia 4-1 in what was a winner-takes-all top-of the table clash, and the Sparrow Hawks pipped Group C runners-up Benin to the finals on goal difference.
Benin's hopes were ruined by a 5-2 hammering by already-qualified Mali.
In April Togo appointed Claude LeRoy as their new manager and he has had a huge impact on them, despite the the threat of a prison sentence hanging over him for alleged involvement in fraudulent transfers at French club Strasbourg.
He is now in line to coach at a record-extending nine Nations Cup tournaments.
Tunisia and Liberia went into their match level on 10 points and everything at stake.
Wahbi Khazri and Taha Yassine Khenissi put the Tunisians 2-0 up in the first half and although Liberia pulled a goal back on 71 minutes, the hosts responded with a quickfire double to assert total control.
Group B also featured a clash between the top two, with the possibility of DR Congo or Central African Republic going through as winners.
But the pressure was on visitors CAR, who needed a victory while DR Congo needed only a point, and it proved too much for the politically-troubled nation as they were soundly beaten 4-1.
Earlier on Sunday, Group E reached its conclusion with two dead rubbers, as Guinea-Bissau had clinched top spot and a best-placed runners-up spot was out of reach for the other teams.
Guinea-Bissau fell to a 1-0 defeat by Congo, while Zambia and Kenya drew 1-1.
And in Group L, Swaziland failed to give themselves a chance of a best-placed runners-up spot as they were beaten 1-0 by Malawi.
Zimbabwe had already qualified as the group winners, so their 1-0 away defeat by Guinea later on Sunday had no bearing on qualification.
Already-qualified pair Algeria and Morocco eased to victories against Lesotho and Sao Tome e Principe respectively.
Algeria won 6-0 in Group J, with two goals each for Leicester City's Riyad Mahrez and Dinamo Zagreb's Hilal Soudani.
Morocco beat Sao Tome e Principe 2-0 to finish Group F on 16 points.