Mexico City's legislative assembly has voted to legalise abortion in the city, the capital of the world's second-largest Roman Catholic country.
Rival demonstrations have been held outside the assembly building
Lawmakers voted 46 to 19 in favour of the bill that will permit abortions of pregnancies in the first 12 weeks.
Mexico City previously allowed abortion only in cases of rape, if the woman's life was at risk or if there were signs of severe defects in the foetus.
Opponents of the abortion law have said they will challenge it in the courts.
The BBC's Duncan Kennedy, in Mexico City, says that for years groups wanting to increase the rights of women have campaigned for change while conservative forces in the Catholic Church and elsewhere have fought to keep the practice outlawed.
Mexico City is one of the most populous cities in the world, with 8.7 million of Mexico's population of 106 million people living there, according to UN figures from 2005.
The abortion vote split Mexico's population, which is 90% Catholic, and prompted a letter last week from Pope Benedict XVI urging Mexican bishops to oppose it.
Prior to the vote, riot police kept rival demonstrators apart as they hurled insults at each other outside the assembly building.
There are an estimated 200,000 illegal abortions in Mexico each year.
Of women who opt for illegal procedures, at least 1,500 women die during botched operations performed in unhygienic backstreet clinics.
Many victims of rape are denied access to legal abortion, a Human Rights Watch report said last year.
The Mexico City assembly has courted controversy in Mexico before: it recently voted to allow same-sex civil unions and is currently considering legalising euthanasia.