Catholic Argentina's lower house has backed a bill legalising abortion in the first 14 weeks of pregnancy.
After a divisive debate lasting more than 22 hours, 129 members of the Chamber of Deputies voted in favour and 125 against while one abstained.
The bill will now have to go to the Senate.
President Mauricio Macri is strongly opposed to the bill but has said that he would not veto it if it was passed by both houses.
Abortion is currently illegal in Argentina, except in cases of rape or when the life or health of the woman is at risk. Women seeking abortions also have to apply to a judge for permission, which critics say can unnecessarily delay the procedure.
Up until three hours before the vote, those against the bill seemed to be in the majority until a lawmaker in the province of La Pampa, Sergio Ziliotto, announced on Twitter that he and two colleagues had changed their minds and would vote "yes".
Junto a Melina Delú y Ariel Rauschenberger, los 3 diputados nacionales peronistas por La Pampa votaremos a FAVOR de la despenalización del aborto.
— Sergio Ziliotto (@ZiliottoSergio) June 14, 2018
End of Twitter post by @ZiliottoSergio
The announcement invigorated pro-choice lawmakers at a time when despondency was beginning to set in after the night-long debate.
Supporters of the bill, many of whom had spent the entire night demonstrating outside of the Congress building in Buenos Aires, cheered and hugged when the result of the vote was announced.
There was high drama even as the result came in. The electronic board inside the chamber initially showed 131 in favour and 123 against but some lawmakers immediately shouted that their vote had not been recorded accurately.
The speaker then proceeded to ask a number of deputies to confirm how they had voted and after some tense minutes confirmed that the bill had been passed.
The bill will now go to the Senate, where it is expected to go to a vote in September.