South Africa booked the last place at the African Cup of Nations finals with a 2-1 away win over Libya thanks to Percy Tau's double on Sunday to complete the lineup for the 24-team finals being hosted in Egypt in June.
The diminutive 24-year-old striker, on loan at second-tier Union SG in Belgium from English Premier League club Brighton & Hove Albion, scored with two powerful second half strikes to ensure the country finished second behind Nigeria in Group E.
Earlier on Sunday, Benin, the DR Congo, Tanzania and Zimbabwe also ensured qualification.
Benin beat neighbours Togo 2-1 in Group D to bring an end to the international career of former Arsenal, Manchester City and Tottenham Hotspur striker Emmanuel Adebayor.
Tanzania secured a convincing 3-0 home victory over neighbours Uganda, who had already qualified.
Tanzania finished second in Group L ahead of the small kingdom of Lesotho, who needed victory away in the Cape Verde Islands to qualify for the first time but were held 0-0.
Zimbabwe finished top of Group G with their 2-0 home win over Congo-Brazzaville, while DR Congo were second in the section after edging Liberia 1-0 in Kinshasa.
Khama Billiat and Knowledge Musona scored first-half goals for the Zimbabweans while Cedric Bakambu was the Congolese hero.
South Africa, who had missed out on the last finals in Gabon two years ago, needed only a draw against Libya, who were forced to host the game on neutral territory in neighbouring Tunisia because of a FIFA ban on them hosting matches at home.
Libya would have qualified at South Africa's expense with a win and they dominated a goalless first half with Manchester-born Ahmed Benali at the centre of their attacks.
But Tau broke the deadlock after 50 minutes with a snap shot before Libya equalised with a Benali penalty in the 65th, but the visitors restored their lead three minutes later when Tau fired in a shot from the left to ensure his country progressed.
Sunday's five qualifiers joined Burundi, Cameroon, Guinea-Bissau and Namibia, who sealed their finals berths in Saturday's action.
On Friday, Angola striker Wilson Eduardo scored on his debut as they beat Botswana 1-0 to qualify.
Finalists: Egypt (hosts), Algeria, Angola, Benin, Burundi, Cameroon, DR Congo, Ghana, Guinea, Guinea-Bissau, Ivory Coast, Kenya, Madagascar, Mali, Mauritania, Morocco, Namibia, Nigeria, Senegal, South Africa, Tanzania, Tunisia, Uganda, Zimbabwe.
The draw for the finals will take place at Sphinx and the Pyramids, near Cairo, on April 12.
Information from Reuters was used in this report.