The Barea scored a goal in each of the two halves to defeat the better rated Nigerians.
The victory means Madagascar top Group B of the AFCON with seven points.
The Super Eagles come second with six points. Both teams secure automatic qualification for the second round of the competition.
Guinea take the third spot in the group with a 2-0 victory over Burundi.
Madagascar, ranked 108th in the world, are competing in the tournament for the first time and were unfancied against the three-time AFCON champions.
But goals from Lalaina Nomenjanahary and Carolus Andriamahitsinoro settled the clash in Alexandria.
The opening goal for Madagascar came in the 12th-minute when John Ogu passed backwards to defender Leon Balogun. The ball was intercepted following an error by Balogun and Madagascar benefitted from the gaffe.
Madagascar doubled their lead in the 53rd minute as Andriamahitsinoro’s free-kick took a wicked deflection off half-time substitute Wilfred Ndidi.
The deflection wrong-footed Ezenwa before bouncing in off the right post.
Before Sunday’s game, Madagascar had never scored against Nigeria let alone secure a win. But on Sunday, they showed just how much they have improved.
Nigeria will now face the second placed team in Group F which houses powerhouses Cameroon and Ghana as well as Benin Republic and Equatorial Guinea.
Tunde Eludini is a graduate of the Obafemi Awolowo University Ile-Ife, Nigeria where he studied International Relations. He is a Senior Correspondent coordinating the sports section for PREMIUM TIMES. Twitter: @tundeyeludini