U.S. District Judge Carlton W. Reeves late Thursday night issued an injunction blocking a bill by the Mississippi legislature that would have allowed private citizens and some public officials professing a “sincere religious belief” to deny services to gays and lesbians.

Just minutes before House Bill 1523 was to take effect at midnight, Reeves eviscerated the bill — the most sweeping attempt by a state to undermine the Supreme Court’s 2015 decision to legalize same-sex marriage — as being in violation of the First and 14th amendments.

“The State has put its thumb on the scale to favor some religious beliefs over others. Showing such favor tells ‘nonadherents that they are outsiders, not full members of the political community, and . . . adherents that they are insiders, favored members of the political community,’ ” Reeves wrote, citing precedent. “And the Equal Protection Clause is violated by HB 1523’s authorization of arbitrary discrimination against lesbian, gay, transgender, and unmarried persons.”

“The plaintiffs’ motions are granted and HB 1523 is preliminarily enjoined.”

Federal courts have now delivered three rulings on gay rights that together compose a devastating, civil-rights-era-style rebuke against Mississippi, a former Confederate state with an oppressive history that has adamantly refused to fall into line behind same-sex marriage, gay adoption and other legal protections for non-heterosexuals.

Coupled with a ruling Reeves filed earlier in the week — preventing circuit clerks from denying marriage licenses to same-sex couples — the proposed law is, for the moment, stillborn.

Mississippi Gov. Phil Bryant (R) said he expects an “aggressive appeal” of Reeves’s ruling.

“Like I said when I signed House Bill 1523, the law simply provides religious accommodations granted by many other states and federal law. I am disappointed Judge Reeves did not recognize that reality. I look forward to an aggressive appeal,” Bryant said in a statement issued by his office Friday morning.

Legislative attempts to curb the rapid expansion of gay rights have spiked sharply over the past few years, with almost 200 bills seen as discriminatory introduced in nearly three dozen states, according to the Human Rights Campaign, an advocacy group.

[The recent surge of bathroom bills is not as sudden as it may appear]

Three of those bills that became law: Mississippi’s measure; legislation in North Carolina restricting bathroom access for transgender people; and a Kansas law, signed this spring, letting religious groups restrict membership.

South Dakota and Georgia passed similar bills; Republican governors in both vetoed them.

Bryan Adams on April 10 canceled a show in Mississippi to protest a new state law that lets people with religious objections deny services to same-sex couples. (Reuters)

The preliminary injunction in Mississippi will hold until any appeals are completed. Then, if upheld, it will be filed as a permanent injunction.

“The federal court’s decision recognizes that religious freedom can be preserved along with equal rights for all people regardless of race, religion, or sexual orientation,” said a statement from Robert McDuff, attorney for one of four groups to file suit against the bill.

Reeves’s decision comes 20 months after he struck down Mississippi’s statutory and constitutional bans on same-sex marriage. It comes three months after U.S. District Court Judge Daniel Porter Jordan III, in the same Jackson courthouse, struck down the state’s ban on gay couples adopting children.

Roberta A. Kaplan, the New York-based lawyer who represented plaintiffs in both the adoption case and the HB 1523 lawsuit, invoked the state’s racially segregated history in hearings in late June in talking about the law.

“There can’t be separate but equal marriage,” she told Reeves. “There can’t be Jim Crow kind of gay marriage in the state of Mississippi.”

Republican Lt. Gov. Tate Reeves (no relation to the judge) had said earlier in the week that he hoped the state would appeal the judge’s initial injunction.

“If this opinion by the federal court denies even one Mississippian of their fundamental right to practice their religion, then all Mississippians are denied their 1st Amendment rights,” he said in a statement. “I hope the state’s attorneys will quickly appeal this decision to the 5th Circuit to protect the deeply held religious beliefs of all Mississippians.”

Reeves, the judge, ripped into that logic in the conclusion of his 60-page opinion.

“Religious freedom was one of the building blocks of this great nation, and after the nation was torn apart, the guarantee of equal protection under law was used to stitch it back together,” he wrote. “But HB 1523 does not honor that tradition of religion freedom, nor does it respect the equal dignity of all of Mississippi’s citizens. It must be enjoined.”

In his 60-page ruling, Reeves wrote that the title, history and text of the law showed it to be “the State’s attempt to put LGBT citizens back in their place.” Officially titled the Protecting Freedom of Conscience from Government Discrimination Act, the law was authored by state House Speaker Philip Gunn (R). After the U.S. Supreme Court’s Obergefell v. Hodges decision last year legalizing same-sex marriage, Gunn said the ruling was “in direct conflict with God’s design for marriage as set forth in the Bible. The threat of this decision to religious liberty is very clear.”

His resulting bill easily passed the Republican-controlled House and Senate. Bryant enthusiastically signed the bill into law April 5.

It sought to protect Mississippians who had three specific religious beliefs: that marriage is between only one man and one woman, that sex is reserved for heterosexual married couples and that gender is determined at birth. Court clerks would be allowed to deny marriage licenses to same-sex couples by asserting a religious offense. A single mother could be fired from her job. Private business owners could refuse service to anyone they perceived to be gay.

Local, national and international outrage ensued.

Mississippi offers no discrimination protections to gay and lesbian residents. Its ban on adoptions by same-sex couples was the last one in the nation. And in 2004, when 11 states passed referendums barring same-sex marriages, Mississippi voted the most strongly against the unions, at 86 percent.

So, although there have been no reported problems in the state with same-sex-marriage licenses being issued, the bill hit a nerve.

“The fear is greater here than in other places,” said Paloma Wu, legal director for the state American Civil Liberties Union, which filed one of the challenges against the law.

State business leaders decried it, newspaper editorials railed against it, and nonprofits, activists and individuals — gay, straight and transgender — filed suit.

In a further symbol of change, Reeves, the judge hearing the case, is an African American who was born in 1964 and grew up in tiny Yazoo City. He obtained his undergraduate degree at Jackson State University, a historically black institution a few blocks from the Capitol building, and was eventually nominated to the bench in 2010 by the nation’s first black president.

His rulings on same-sex marriage have stymied the most powerful politicians in the state — all white men who grew up here, like he did, in the waning days of segregation.

Joseph R. Murray II, a New Jersey native and once a lawyer for the ultra-conservative American Family Association, based in Tupelo, Miss., later came out as gay. He married in Mississippi last year (without incident), practices law in Ripley (population 5,000), and counts himself as a devout Catholic and Donald Trump supporter. He recently wrote a commentary for the Clarion-Ledger, the state’s largest newspaper, mocking Republican state leaders for being “obsessed” with homosexuality.

“The politics are just so blatant” in the legislature, he said in an interview. “This bill, it’s the death throes of the religious right that doesn’t know what to do with itself now that it’s lost, and lost miserably. They took all those $5 and $10 donations from little old ladies, and what have they got to show for it?”