Chile's Constitutional Court on Monday approved a bill to decriminalize abortion in certain cases, a move decried by conservative opponents but hailed by Socialist President Michelle Bachelet as a victory for women's rights.
The bill will allow abortion in cases of rape, threat to the mother's life or deadly birth defects.
Judges voted by six to four to dismiss challenges brought by conservative parties opposed to the reform, the court's secretary-general Rodrigo Pica told a news conference.
The bill can now be signed into law by the socialist president, who launched the reform in 2015.
Citizens for and against the reform staged rowdy demonstrations near the court during its deliberations.
Supporters of the bill celebrated outside the court after the ruling, yelling their thanks to Bachelet.
Rival demonstrators shouted curses, calling those behind the reform "murderers."
"They are banding together against the life of the just and condemning the blood of the innocent," they chanted.
Bachelet hailed the ruling, in a speech at the presidential palace.
"The women of Chile have won back the basic right to decide for ourselves in extreme cases, particularly cases that can be very painful," she said.
"Today it is women who are the winners. I believe that today democracy once again has won, and Chile has won."
Opponents of the reform said it violates the fetus's right to life enshrined in the constitution.
A recent survey of 705 people by polling firm Cadem indicated that 70 percent of Chileans support legalized abortion under those three conditions, however.
Under current law, abortion is punishable by up to five years in prison.
Abortion under any circumstances was strictly outlawed in Chile in 1989, during the final days of the Augusto Pinochet dictatorship.
Prior to that, for more than 50 years, abortion was permitted if the mother's life was in danger or if the fetus was not viable.
The reproductive rights group MILES hailed Monday's decision as "historic."
"Today we women are conquering new ground for dignity, freedom, independence and equality," it said in a statement.
The reform brings Chile into line with most other Latin American countries in decriminalizing abortion in the three cases mentioned.
A handful of countries in the region still have total bans on abortion, notably El Salvador, Honduras and Nicaragua.
The approval comes ahead of Chile's November presidential elections. Bachelet, who is not a candidate, leaves office in March 2018.
Two years ago, Bachelet succeeded in getting a law approved by congress recognizing same-sex civil unions, and she hopes to extend that soon to include full same-sex marriages.
A pediatrician by profession, Bachelet returned to office in March 2014 after serving as Chile's first woman president from 2006 to 2010.
She was a senior United Nations official working on female empowerment issues after her first term in office.
During her second term, she has seen her support wane due to administration scandals.
Opinion polls indicate that in November voters will likely re-elect right-wing former president Sebastian Pinera.
The election campaign period officially started on Monday.