The measure has roused fierce passions in the homeland of Pope Francis, and the vote was tight: 129 to 125.
Argentina now allows abortion only in cases of rape or risks to a woman's health.
Crowds of supporters and opponents of the measure - kept separate by officials - watched the debate on large screens set up outside Congress.
Feminist groups lobbied hard for the measure and demonstrators who had spent the night awaiting the vote in sleeping bags and folding chairs cheered and sang when the result was announced.
Backers of the measure said legalizing abortion would save the life of many women who now turn to dangerous illegal abortions. The Health Ministry estimated in 2016 that the country sees as many as half a million clandestine abortions each year, with dozens of women dying as a result.
The Roman Catholic church and other religious organizations opposed it, saying it violates Argentina law "that guarantees life from the moment of conception."
President Macri, who has said he opposes voluntary abortions, promised that he would not veto the measure if it is adopted.
Efforts to ease or tighten abortion restrictions have repeatedly emerged across Latin America in recent years.
Neighboring Chile's Constitutional Court last year upheld a measure that would end that country's absolute ban on abortions, permitting abortions when a woman's life is in danger, when a fetus is not viable and in cases of rape. Chile had been the last country in South America to ban abortion in all cases, though several nations in Central America still have absolute prohibitions.
Cuba, Guyana, Puerto Rico and Uruguay permit early-term elective abortions, as does Mexico City.
Copyright 2018 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.