Uruguay has become the second country in Latin America, after communist Cuba, to legalise abortion for all women.
With a 17-14 majority, the Uruguayan Senate approved legislation that allows women to have an abortion in the first 12 weeks of pregnancy.
The measure has divided opinion in the predominantly Roman Catholic country.
Pro-choice and anti-abortion campaigners criticised the compromise that sealed the deal set to be signed into law by President Jose Mujica.
The proposal had already been approved by the lower house of Congress and the Senate, but politicians from both sides of the debate agreed further changes and held another vote.
Abortions versus adoptions
Pro-choice campaigners say many lives will be saved with the end of clandestine, high-risk terminations.
"With this law, we are joining the ranks of developed countries that have largely adopted a stance to liberalise, recognising the failure of criminal laws to avoid abortions," said government Senator Luis Gallo.
Pro-choice campaigners reject changes to the proposal that forces women to justify before a panel of experts why they wish a termination.
After that, they will need to wait for several days - a period of reflection - before being able to state their final decision.
Anti-abortion politicians said the government should have adopted measures to encourage adoptions, rather than change the law.
"Abortion is not a medical act. It does not seek to protect and preserve a patient's health," said opposition Senator Alfredo Solari.
Abortion is legal and available on request in Cuba.
Abortion is also allowed up to the 12th week of pregnancy in many Mexican states and in the area of the capital, Mexico City.
In other Latin American countries, it is only allowed in cases of rape or health risk for the woman.