Benin, the Democratic Republic of Congo, Tanzania and Zimbabwe also secured places on the final day of qualifying to complete the 24-team line-up for the tournament in Egypt.
Tau put South Africa ahead on 49 minutes with a shot from the edge of the box in a match moved to Tunisian city Sfax because of the Libyan security situation.
While a draw would have sufficed for South Africa, Libya had to win the Group E clash to finish runners-up behind Nigeria and qualify.
The north Africans equalised on 65 minutes when Keet accidently fouled giant Libyan substitute Anis Saltou and Ahmad Benali converted the penalty.
But Belgium-based Tau struck again four minutes later with a low shot past long-serving goalkeeper Mohamed Nashnush for what proved the match winner.
Tempers flared several times among the players and the pitch was littered with bottles flung from the stands by the time the match ended.
Nigeria, who wound up their schedule with a 3-1 home win over the Seychelles in Asaba Friday, finished with 13 points, South Africa 12, Libya seven and the Seychelles one.
The South African victory followed a huge media build-up and was a huge relief to supporters frustrated by the constant failures of the team to make an impact in the Cup of Nations.
It was only the second time Bafana Bafana (The Boys) qualified for the biennial tournament since 2008 and England-born coach Stuart Baxter accepted that his job was on the line.
- Careless defending -
Former African champions South Africa also competed at the 2013 finals, but that was due to them replacing violence-torn Libya as hosts.
Elsewhere, Khama Billiat scored direct from a free-kick and Knowledge Musona punished careless defending to give Zimbabwe a 2-0 Group G victory over Congo Brazzaville in Harare.
DR Congo finished runners-up in the section thanks to a 1-0 home win over Liberia in Kinshasa with China-based Cedric Bakambu netting seven minutes into the second half.
Benin needed one point to go through from Group D with Algeria, but took all three against Togo with Steve Mounie from Huddersfield Town scoring on 83 minutes for a 2-1 victory.
David Djigla gave Benin an early lead in Cotonou and former Arsenal, Manchester City and Tottenham Hotspur striker Emmanuel Adebayor levelled 19 minutes from time.
Tanzania hammered previously unbeaten and already qualified Uganda 3-0 in Dar es Salaam to secure second place in Group L ahead of Lesotho, who could only draw 0-0 in Cape Verde.
Saimon Msuva broke the deadlock midway through the first half before a capacity 60,000 crowd as Denis Onyango conceded his first goal of the six-match qualifying campaign.
Erasto Nyoni netted off a 50th-minute penalty to double the lead and any thoughts Uganda had of a comeback were dashed soon after when Aggrey Morris scored a third goal.
Teams who qualified ahead of the final matchday were Burundi, Cameroon, Egypt, Algeria, Angola, Ivory Coast, Ghana, Guinea, Guinea-Bissau, Kenya, Madagascar, Mali, Mauritania, Morocco, Namibia, Nigeria, Senegal, Tunisia and Uganda.
Egypt hold the record for Cup of Nations titles with seven and home advantage will ensure they are among the favourites to win the June 21-July 19 tournament.