A federal court has struck down a Trump administration rule that allowed health care providers to refuse to treat patients if they cite a sincerely held religious belief.

The ACLU and the NYCLU argued on behalf of two public health organizations that a Department of Health and Human Services (HHS) rule violated federal law.

Related: Anti-LGBTQ Christian hate group cheers as Trump administration shuts down HIV cure research

This past May, HHS issued a rule allowing health care workers to refuse to provide service if they cite their religious beliefs and punishing health care organizations that don’t allow their workers adequate “religious freedom.”

LGBTQ organizations balked at the rule change since queer and transgender people are likely to be on the receiving end of religion-based discrimination. Reproductive freedom and public health organizations also sounded the alarm about the rule.

Now Judge Paul Engelmayer of the U.S. District Court for the Southern District of New York has ruled against HHS, saying that the department overstepped its authority in issuing the rule, which would’ve gone into effect on November 22.

The rule, he wrote, violates Title VII of the Civil Rights Act because it would allow workplace discrimination and also violates the Emergency Medical Treatment and Labor Act, an anti-patient dumping law.

Engelmayer also noted that HHS couldn’t show why the rule was needed to protect religious freedom, calling the rule “a classic solution in search of a problem.”

Lastly, the judge said that the rule overstepped HHS’s authority when it came to funding, since the rule allows the department to cut funding to health care providers that don’t allow their workers to discriminate. No Congressional law allows HHS to make that sort of funding decision.

Engelmeyer didn’t rule that HHS violated the Establishment Clause of the Constitution, which bans the government from promoting a specific religion.

The judge also noted in his ruling that some of the Trump administration’s arguments “cannot be taken seriously.”

“Today’s decision is an important victory against the Trump Administration’s cruel and unlawful attempts to roll back critical patient protections,” said the ACLU’s Alexa Kolbi-Molinas. “Everyone is entitled to their religious beliefs, but religious beliefs do not include a license to discriminate, to deny essential care, or to cause harm to others.”

“The so-called ‘Conscience Rule’ was part of the Trump Administration’s broader attempt to allow health care providers and other programs funded by HHS to prioritize their personal religious beliefs over the needs of the Americans they should be serving,” said Stan J. Sloan, CEO of Family Equality. “Health care is a basic right and this rule would have allowed health care providers to discriminate openly, placing at risk the ability of millions of Americans to access critical services, including over 11 million LGBTQ+ people and their children.”

This rule is separate HHS’s rule that allows adoption agencies and other recipients of federal grant money to discriminate, which was issued last week. It is also separate from HHS’s attempts to overturn an Obama administration rule that banned discrimination against transgender people when it comes to health care.

Another legal challenge to the same rule is currently being heard in a federal court in California.