A federal judge ruled Utah’s ban on same-sex marriages unconstitutional Friday, writing in his opinion that it “perpetuates inequality.”

“The State’s current laws deny its gay and lesbian citizens their fundamental right to marry and, in so doing, demean the dignity of these same-sex couples for no rational reason,” Judge Robert J. Shelby, of the United States District Court for the District of Utah, wrote in his opinion. “Accordingly, the court finds that these laws are unconstitutional.”

Another southwestern state, New Mexico, became the 17th state to allow same-sex marriage on Thursday, when its Supreme Court ruled a ban there unconstitutional as well.

Nationally, public opinion on the issue has flipped over the past decade. In 2003, 55 percent opposed gay marriage, while 37 percent supported it. Today, 58 percent support it, while 36 percent oppose, according to data compiled by The Post’s Masuma Ahuja and Emily Chow.

But public opinion on the issue in Utah has been historically slower to turn. Only 28 percent supported legalizing gay marriage in a February 2012 poll conducted by the Center for the Study of Elections and Democracy, while a similarly timed CBS/New York Times poll found 38 percent support nationally. The Utah poll found that 43 percent preferred civil unions, while 24 percent said the same nationally.

Utah’s large Mormon population is particularly opposed to homosexuality. Nationally, nearly two in three Mormons in 2011 said society should discourage homosexuality, while only about one in three overall said so, according to a Pew poll. And nearly three-fifths of Utah’s residents are Mormon, according to a 2007 Pew Religion & Public Life survey.

The state is also home to fewer self-described gays than most other states. Just 2.7 percent of Utahns identified as gay, lesbian, bisexual or transgender in 2012 Gallup surveys, compared with a national average of 3.5 percent.

(Peyton M. Craighill and Scott Clement contributed.)