The ruling, which comes against the background of US State Department reports of widespread harassment of homosexuals in Mexico, overturned earlier rulings by American immigration courts which had insisted he be sent home.
Jose Boer-Sedano, 45, came to the US in 1990 on a six-month visa and has stayed ever since saying he dare not return to his home town of Tampico in the eastern Mexican state of Tamaulipas. He works in San Francisco as a waiter.
Mr Boer-Sedano said he had been stopped nine times by a senior police official in his town and forced to perform oral sex under threat of being exposed as gay. The police officer allegedly also spoke of having him killed.
"Despite his attempts to conceal his sexuality, others could perceive it and Boer-Sedano was ostracised by his family, friends, and co-workers on that basis," the court said. "His family refused to allow him to interact with other family members or his friends, fearing [he] would be a 'bad influence' on them."
The court has made similar rulings in other cases involving homosexual and transgender asylum-seekers from Central and Latin America, because of concerns they would face persecution at home inflicted or condoned by the police.
Since 1990 there has been some progress in establishing rights for homosexuals in Mexico. However, more general social acceptance is a far more distant prospect for gays and lesbians in Mexico than in the US.