Niger have qualified for their maiden Africa Cup of Nations finals despite losing 3-0 in Egypt on Saturday.
Group G rivals South Africa or Sierra Leone would have qualified had either won their 0-0 draw.
South Africa initially thought they were through, with the FA president going on television to congratulate the team, before finding out the bad news.
Libya went through as best runners up, but Nigeria exited, failing to qualify for the first time since 1986.
Niger, South Africa and Sierra Leone all ended with nine points in Group G, but Niger qualify thanks to their superior head-to-head record against their rivals.
Zambia and Libya have both qualified from Group C after a 0-0 draw in Chingola. Nigeria went out after being held to a 2-2 draw by Guinea in Abuja. Ibrahima Traore's goal deep into stoppage time ensured Guinea's progress from Group B.
Equatorial Guinea and Gabon will co-host the tournament, which starts on 21 January and ends on 12 February, with a number of Premier League players set to be away from their clubs during the competition.