Mexico's Supreme Court has voted to uphold a law allowing same-sex marriages in the capital, Mexico City.
Eight of the 10 justices at the country's highest court said the law was constitutional.
Hundreds of gay and lesbian couples have been married since it was passed seven months ago.
Federal prosecutors had challenged the law, saying it went against the principle of protection of the family.
But the Supreme Court justices said nowhere in the constitution was it defined what a family was.
It is not yet clear whether the ruling could pave the way for same-sex marriages across Mexico.
Mexico City's local assembly passed the law in December, giving gay people full marital rights, including the right to adopt.
It was one of the first Latin American capitals to fully recognise same-sex marriages.
However, it has drawn opposition from the Catholic Church and conservative groups.
So far in Latin America, only Argentina has legalised gay marriages nationwide.
On Monday, Mexico's Supreme Court will discuss the legality of gay couples' right to adopt.