MEXICO CITY — His church turned him away, his family discouraged him from a public fight and the government of the state where he lives vowed it would never happen.

But it did. Hiram Gonzalez married his boyfriend, Severiano Chavez, last year in the northern state of Chihuahua, which, like most Mexican states, technically allows marriage only between a man and a woman.

Mr. Gonzalez and dozens of other gay couples in recent months have, however, found a powerful ally: Mexico’s Supreme Court.

In ruling after ruling, the court has said that state laws restricting marriage to heterosexuals are discriminatory. Though the decisions have been made to little public fanfare, they have had the effect of legalizing gay marriage in Mexico without enshrining it in law.