The law, which must still officially be announced by President Hery Rajaonarimampianina, received unanimous backing from the 82 deputies on Wednesday in the island nation's capital Antananarivo.
While the EU hailed the "historic step" taken by lawmakers, prisoners in Madagascar given capital punishment have since 1958 in practice served life sentences.
Under the new law, which states "no one can be executed," the death penalty will be replaced by forced labour for life.
The vote was the culmination of efforts begun in 2012 when the then-transition president Andry Rajoelina signed a UN agreement that aimed to end capital punishment.
Madagascar's abolition of the death penalty is "the result of an intense plea from Madagascan and international civil society," the EU's representative in Madagascar said in a statement.