Mexico City's legislature has for the first time approved gay marriage.
"It was approved overall by 39 votes in favor and 20 against, with five abstentions," said a spokesman for the bill's chief sponsor, assemblyman Davi Razu.
Spokesman Oscar Oliver said the city's majority leftist legislators also defeated an opposition amendment to the gay marriage bill that would have prevented same-sex couples from adopting children.
"For centuries, unjust laws prohibited marriage between whites and blacks or Europeans and (indigenous) Indians," Democratic Revolutionary Party (PRD) lawmaker Victor Romo said.
"Today all those barriers have come down."
The new measure modified a civil union law already on the books in Mexico City, as in other Latin American nations including Uruguay and Colombia.
In Argentina the Supreme Court is to rule on a court-approved gay marriage that was challenged earlier this month.
The Mexico City law changes the meaning of marriage from "a free union between a man and a woman" to "a free union between two people."
Mexico City's gay marriage bill was fully backed by lawmakers from the PRD, which has ruled Mexico's sprawling capital since 1997. It was opposed by the country's ruling National Action Party (PAN).
The vote was preceded by a lively, three-hour debate during which President Felipe Calderon's conservative PAN issued a statement calling the gay marriage bill "an electoral ploy by the PRD that mocks and abuses the gay community."
Outside the city's assembly building, about 100 gay rights activists demonstrated in favor of the marriage bill, some holding up signs saying: "Be Happy, Be Gay."
"We've got to celebrate. It's a social and cultural breakthrough that acknowledges a historic debt owed the gay community," said Antonio Medina, an activist and editor for the gay-news agency Notiese.
"Let's hope the conservatives won't manage to reverse it by taking it before the Supreme Court of Justice," he told AFP, as some homosexual couples celebrated the law by hugging and kissing.
Under the new law, same-sex marriages can be officiated 45 days after the approval of the measure, beginning in February, gay rights activists said.
Before Monday's vote, Mexico City was among a handful of Latin American cities that allowed gay unions.
An opinion poll in September showed the city population divided on the issue of gay marriage, with 48 percent in favor and 46 percent opposed.
The Roman Catholic Church in Mexico has strongly opposed the gay marriage bill since it was taken up by the city legislative assembly in September.
Vatican former health minister Javier Lozano Barragan, a Mexican cardinal, earlier this month said that homosexuals and transsexuals "will never make it to the kingdom of heaven."
Buenos Aires, known for its active if low-key gay movement, became the region's first city to approve civil unions for gay couples in 2002, granting them some but not all the rights enjoyed by heterosexual married couples.
Elsewhere in Latin America, the Mexican state of Coahuila and the Brazilian state of Rio Grande do Sul also allow civil unions for same-sex couples.
In late 2007, Uruguay became the first country in the region to legalize civil unions for gays. In January 2009, the Colombian Constitutional Court recognized a series of civil union rights for homosexual couples, including social welfare rights.
But no Latin American country authorizes marriage between gays.