Mexico City's assembly has backed a law recognising same-sex civil unions, the first such move in the country's history.
Gay rights protesters demonstrated while legislators voted
The ruling stops short of enabling gay couples to get married and will only apply to the estimated nine million inhabitants of Mexico City.
Mexico City Mayor Alejandro Encinas is widely expected to ratify the law.
It has met fierce opposition from President-elect Felipe Calderon's National Action Party.
The law has also been attacked by the Catholic Church and conservative activists.
While Mexico City legislators voted for the law, supporters and opponents of the bill demonstrated noisily outside the assembly building.
Protester Humberto Muniz described the law as "anti-natural".
"Societies have always fallen into decadence when there has been homosexuality," he told the Reuters news agency.
But the vote was welcomed by David Sanchez, an openly gay congressman.
"These reforms are going to cause a snowball effect that no one will be able to stop," he told Reuters.
Under the law, Mexico City's gay couples who register their union with civil authorities will gain access to inheritance and pension rights.
Unmarried heterosexual couples can also register under the same law.
Gay civil unions have yet to be approved by local legislators in any other part of Mexico.
A similar bill is being debated by lawmakers in Mexico's northern state of Coahuila, bordering Texas.