A goal from Thailand-based Njiva Rakotoharimalala sent Madagascar to their first ever Africa Cup of Nations finals.
The 26-year-old midfielder scored the only goal of the game just before half-time as the Malagasy beat visiting Equatorial Guinea.
The result puts Madagascar on ten points in Group A to guarantee them a place in Cameroon next year.
Senegal will join them in the finals if they can win in Sudan later on Tuesday.
The games was played in the city of 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.
There were two drawn matches in Group B as Comoros grabbed a 2-2 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 Amrabaat to take the lead.
The hosts kept battling and Ben Mohamed was on target again in injury time at the end of the match to earn a point for Comoros.
The results mean that Cameroon top the group with eight points, but they have qualified automatically as the Nations Cup 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.
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 decision.
The loss means that South Sudan remain without a single point and cannot reach next year’s Nations Cup.
Burundi took the lead in Bujumbura through striker Fiston Abdul Razak before Mamadou Fofana levelled the score for the visitors.
Mali lead the way with eight points just one ahead of Gabon with Burundi third on six points.
Egypt secured a 2-0 win over eSwatini (formerly Swaziland) in Group J.
The win came thanks to a headed goal from Ahmed Hegazi after 19 minutes and well worked team goal that was finished by Marwan Mohsen early in the second half.
The Pharaohs are now on the verge of qualifying for the finals with nine points while eSwatini cannot now qualify.
There are two more qualifying rounds left to play one in November and the final matches will be in March next year.