A goal from Thailand-based Njiva Rakotoharimalala sent Madagascar to their first ever Africa Cup of Nations (Afcon) finals.
The 26-year-old midfielder scored the only goal just before half-time as the Malagasy beat visiting Equatorial Guinea.
The result puts Madagascar on 10 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 (Caf) 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.
Was on target
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 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.
Remain in contention
The top two teams in each of the 12 qualifying groups will progress to the 2019 Africa Cup of Nations in Cameroon
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.
The final matches
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.