In a move that may put it at odds with the rest of the country, the Mexico City Legislature approved a far-reaching gay-rights bill Monday, voting to allow people of the same sex to marry and to adopt children. The leftist-dominated legislature of this capital city of about 20 million people turned aside opposition from the Roman Catholic Church and ended lively debate to approve the measure by a 39-20 vote. Mayor Marcelo Ebrard is expected to sign the bill into law. 'Mexico City has put itself in the vanguard,' legislator Victor Hugo Romo said. 'This is a historic day.' Mexico City's initiative goes further than anything in Latin America by rewriting the law to re-define 'marriage' as a 'free union between two people' instead of between a man and a woman. It gives homosexual couples the same rights as heterosexual pairs, including the right to adopt, inherit, obtain joint housing loans and share insurance policies. Several countries, most of them in Europe, and a handful of U.S. states have legalized same-sex marriage in recent years, and the issue is being hotly debated in parts of predominantly Catholic Latin America. Uruguay was the first Latin American country to recognize same-sex unions, as well as adoptions by gay couples, and some cities in Argentina have adopted similar measures. Proponents praised the removal of stigma and discriminatory practices that hurt gays, while opponents decried what they called an affront to the traditional institution of family. 'This is wonderful,' said gay-rights activist Judith Vasquez from the noisy legislature floor, where proponents chanted, 'Yes, we could!' and waved rainbow flags. Gay 'couples have effectively been together for years, decades, centuries. But now it is our right.' Most of the opposition in the city's legislature came from President Felipe Calderon's conservative National Action Party, which has threatened to take the city to court if Ebrard does not veto the measure. Also opposed was the church, which labeled the proposal immoral, saying marriage must hold the promise of procreation, something that is possible only between a man and a woman. Cardinal Norberto Rivera Carrera said the law created the 'perverse possibility' that 'innocent children' would be adopted by gay couples. 'It is an aberration,' activist Jorge Serrano Limon said. 'Marriage cannot be between men. That is absurd.' Mexico City, as a rule, is more permissive than much of the rest of the country, relatively open to sexual freedoms and expressions. Under Ebrard and his Democratic Revolution Party, which controls the local legislature, the city has been at the forefront of social policy, often taking stances a far distance from other parts of Mexico. The city, for example, legalized abortion in 2007, a decision that has since backfired and prompted states around the country to dig in their heels against abortion. It was unclear when Ebrard planned to sign the gay-rights bill into law. 'They have given Mexicans a very bitter Christmas,' said Armando Martinez Gomez, president of the College of Catholic Attorneys. 'They have eliminated the word `father' and `mother.' ' He called on Ebrard to veto the bill, which he noted went even further than the city executive had intended when legislators removed a clause that would have forbidden adoption. National Action Party lawmakers also demanded Ebrard exercise his veto. Martinez and other opponents had sought a city-wide referendum on the issue instead of a vote in the legislature. He said surveys taken by his organization showed overwhelming opposition to same-sex marriage. (Another survey published last week by the Reforma newspaper showed opinion more evenly divided.) He also predicted a backlash against gays. 'There will be repercussions, the unleashing of homophobia,' he said. 'Ours is not a very tolerant society.' Before Monday's vote, Mexico City already had on the books a law that allowed a legal union between unmarried people, under which they could avail themselves of a limited number of services and benefits. Only 680 couples have used the law since it went into effect in 2007. It was not clear how many gays and lesbians might be expected to rush to the altar or, as required in Mexico, the judge's chambers. 'For centuries, unfair laws prohibited marriage between whites and blacks, between Europeans and Indians,' said Romo. 'Today, all the barriers have disappeared.' Staff writer Ken Ellingwood contributed to this report. 