The Uruguayan Senate has voted to decriminalise abortion in the first 12 weeks of pregnancy - a rare step in a Latin American country.
The measure, approved last week by the lower house, passed by 17 votes to 13.
The bill's backers say it will reduce the number of women dying because they have to resort to illegal abortions.
But President Tabare Vazquez, himself a doctor, has said he opposes abortion on medical and ethical grounds, and he is expected to veto the bill.
Under the current law, women who have an abortion and the people who assist them face prison.
Abortion is only allowed in the case of rape or when the life of the woman is in danger.
Moves to decriminalise abortion have provoked fierce debate in Uruguay
The new legislation would allow women to terminate their pregnancies in the first 12 weeks for these reasons but also under certain other circumstances, such as extreme poverty.
However, the measure is unlikely to take effect as President Vazquez has said he will veto the bill.
It would need a three-fifths majority in Congress to override a presidential veto.
The Roman Catholic Church in Uruguay had warned lawmakers voting for the bill that they could face ex-communication.
But the bill's backers said the vote was a "milestone" for women's rights in Uruguay.
"Whether the president vetoes it or not, it's important that Congress has established this right," Margarita Percovich, a senator from the governing party, told Reuters.
Recent opinion polls suggest a majority of Uruguayans favour easing restrictions on abortion.
Most Latin American countries allow abortion only in cases of rape, when the woman's life is in danger or if the foetus is severely deformed.
But both Cuba and Mexico City (though not the rest of Mexico) allow abortions without restriction in the first 12 weeks.