MEXICO CITY  The Mexican Supreme Court ruled Tuesday that each of the country’s 31 states must recognize same-sex marriages registered in Mexico City, potentially giving gay and lesbian couples full matrimonial rights nationwide.

The court had already ruled this month that Mexico City’s same-sex marriage law, which took effect in March and has resulted in hundreds of same-sex marriages, was constitutional.

But on Tuesday, the court went a step further, ruling 9 to 2 against a complaint from the attorney general’s office, which had said that other jurisdictions should not be required to honor marriages that were performed in Mexico City.

While the court made it clear that state governments were not obligated to enact same-sex marriage laws of their own, it did require them to recognize the legality of such marriages performed in Mexico City.