They were later joined by Egypt, Senegal and Tunisia in qualifying for the finals in Cameroon next June/July.
Madagascar’s win moved them to 10 points in Group A with two matches left to play.
The games was played in Vontovorona after Madagascar were banned from using the Mahamasina Stadium in Antananarivo for “three matches or three months”.
The suspension was imposed by the Confederation of Africa Football following a stampede at the national stadium in September, when one person was killed and nearly 40 others were injured.
Madagascar become the 40th different nation to qualify for the Nations Cup finals.
Senegal left it late to get the win they needed in Sudan to clinch a place in the finals alongside Madagascar from the group.
Lorient’s Sidi Sarr scoring in the 86th minute just three minutes after coming on in Khartoum as a substitute.
|Group A after four matches:|
|Senegal||10 points (qualified)|
|Madagascar||10 points (qualified)|
|Equatorial Guinea||3 points (eliminated)|
|Sudan||0 points (eliminated)|
Egypt and Tunisia helped each other to qualify for next year’s expanded finals as they both won in Group J.
Egypt secured a 2-0 win over eSwatini (formerly Swaziland) thanks to a header from Ahmed Hegazi after 19 minutes and a well-worked team goal finished by Marwan Mohsen early in the second half.
The Pharaohs’ qualification was confirmed later on Tuesday as Tunisia maintained their 100% winning record with a 2-1 victory over Niger 2-1 in Niamey.
Sfaxien’s Firas Chaouat scored two goals in a four-minute period in the first half on his international debut for Tunisia.
Niger’s Youssef Oumarou grabbed what turned out to be a consolation for the hosts.
|Group J after four matches:|
|Tunisia||12 points (qualified)|
|Egypt||9 points (qualified)|
|eSwatini||1 point (eliminated)|
|Niger||1 point (eliminated)|
There were two drawn matches in Group B as Comoros grabbed a 2-2 draw against visiting Morocco and Malawi held Cameroon to a goalless draw in Blantyre.
El Fardou Ben Mohamed, who plays for Serbian side Red Star Belgrade, opened the scoring after just eight minutes to give Comoros a shock lead.
The Moroccans then fought back with two second-half goals from Khalid Boutaib and Nordin Amrabat to take the lead.
The hosts kept battling and Ben Mohamed was on target again in injury time to earn a point for Comoros.
The results means that Cameroon top the group with eight points, but they qualify automatically as hosts, leaving just one more place up for grabs from the group.
Morocco lead the way in the race to the finals on seven points, Malawi move to four points and Comoros are on two – with all the teams having played four matches.
|Group B after four matches:|
|Cameroon||8 points (qualify as hosts)|
Three teams remain in contention to qualify from Group C after Gabon beat hosts South Sudan 1-0 and Burundi held visiting Mali to a 1-1 draw.
Midfielder Andre Biyogo Poko, who plays in Turkey for Goztepe, won the match for Gabon with a goal five minutes after half-time.
Gabon played without Arsenal striker Pierre-Emerick Aubameyang after he did not travel with the team to Juba. No official reason has been given for his absence.
Burundi took the lead in Bujumbura through striker Fiston Abdul Razak before Mamadou Fofana levelled the score for the visitors.
|Group C after four matches:|
|South Sudan||0 points (eliminated)|
Algeria missed out on the chance of qualifying from Group D as they lost 1-0 in Benin.
The match-winner was scored by Sessi D’Almeida, who plays in the fourth tier of English football with Yeovil Town, after 16 minutes.
Benin held on for the win despite playing the final 35 minutes of the match with 10 men after veteran Stephane Sessegnon was shown a red card.
Togo managed to take advantage of Algeria’s slip with a late 1-0 win in The Gambia – Fulham’s Floyd Ayite with the winner in injury time after they had Djene Dakonam sent off with 15 minutes left.
|Group D after four matches:|
|The Gambia||2 points|
Nigeria moved to the top of Group E with a narrow 3-2 win over hosts Libya.
The match was played in the Tunisian city of Sfax because of the ongoing security concerns in Libya.
The Super Eagles looked set for a comfortable win as Odion Ighalo and Ahmed Musa put Nigeria 2-0 up inside 20 minutes.
Libya fought back to level through Mohamed Zubya and Italy-based Ahmad Benali who scored after 74 minutes.
Igahlo’s second of the night and fifth against Libya in the past four days gave Nigeria all three points and kept them on course to qualify for the finals.
South Africa laboured to a goalless draw in Seychelles just three days after they had thrashed the same side 6-0 in Johannesburg.
Seychelles can no longer qualify for the finals.
|Group E after four matches:|
|South Africa||8 points|
|Seychelles||1 point (eliminated)|
Zimbabwe missed out on the chance of sealing qualification from Group G after they were held to a 1-1 in Harare by DR Congo.
The Warriors took the lead after just one minute through Ovidy Karuru but that was cancelled out before half-time with an own goal from Teenage Hadebe.
A win would have seen Zimbabwe through to the finals because later in the day Congo Brazzaville lost 2-1 in Liberia.
All three goals came in an opening 15 minute flurry with Liberia racing to a 2-0 lead with goals from Teah Dennis and Wydad Casablanca striker William Jebbor.
Prince Ibara, who also scored against Liberia on Thursday, pulled one back a minute after Jebbor’s goal to give Congo some hope but Lone Star held on for a crucial win.
|Group G after four matches:|
|DR Congo||5 points|
|Congo Brazzaville||4 points|
Guinea and Ivory Coast remain the favourites to qualify from Group H despite both being held to away draws.
Ivory Coast were held to a goalless draw in Bangui by Central African Republic while in Kigali it was 1-1 between Rwanda and Guinea.
Guinea took the lead in the first half through Jose Kante but Jacques Tuyisenge ensured the points were shared with a late equaliser.
The Syli Nationale had to play the second half without Liverpool’s Naby Keita, who was helped from the pitch with an injury.
Wins for Guinea and Ivory Coast would have taken both teams through to next year’s finals.
|Group H after four matches:|
|Ivory Coast||7 points|
|Central African Republic||4 points|
Mauritania are another team who could qualify for their first Nations Cup finals after a 1-0 win over Angola in Group I.
The only goal of the game in Nouakchott was scored by Adama Ba, who plays in the second tier in Turkey for Giresunspor, after 18 minutes.
Botswana are out of contention despite holding on for a goalless draw against visiting Burkina Faso.
|Group I after four matches:|
|Burkina Faso||7 points|
|Botswana||1 point (eliminated)|
Namibia’s 1-0 win over Mozambique moved them level at the top of Group K alongside Guinea-Bissau, who beat Zambia 2-1 on Sunday.
Peter Shalulile gave the Brave Warriors the win in Windhoek with a goal in the final 20 minutes of the match.
The Namibians played the last few minutes with 10 men after Denzil Haoseb was sent off for a second yellow card.
|Group K after four matches:|
Uganda took a big step towards qualifying for a second successive Nations Cup as neighbours Tanzania kept their hopes alive in Group L.
Croatia-based striker Farouk Miya scored both goals for Uganda as they beat hosts Lesotho 2-0.
His first in Maseru came after just six minutes and he added a second from a curling free-kick 10 minutes before half-time.
Tanzania recovered from a missed penalty to record a 2-0 win over Cape Verde in Dar es Salaam.
Saimon Msuva tapped in from close range for the first with Mbwana Samatta, who plays in Belgium with Genk, adding the second.
|Group L after four matches:|
|Cape Verde||4 points|
There are two more qualifying rounds left to play – one in November and the final matches will be in March next year.