A federal judge in New York has struck down a Trump administration rule allowing health care providers to opt out of procedures to which they have religious or moral objections, a policy that threatened care for LGBTQ people and others.

The rule, finalized by the Department of Health and Human Services in May, was to take effect November 22. But Wednesday, the U.S. District Court for the Southern District of New York “found the rule conflicts with Title VII, which prohibits workplace discrimination, and the Emergency Medical Treatment and Labor Act, an anti-patient-dumping law that requires providers to care for people who come to emergency departments suffering from emergency medical conditions regardless of their ability to pay,” Bloomberg Law reports.

Judge Paul A. Engelmayer also ruled that the rule was “arbitrary and capricious,” as there was no evidence that it was necessary on top of policies that already existed to assure that health care workers didn’t have to provide services that violated their conscience.

The decision came in suits filed by New York City, New York State, several other states and cities, Planned Parenthood Federation of America, the National Family Planning and Reproductive Health Association, and other health groups. In California, several civil rights groups, including LGBTQ organizations, have filed a separate suit.

Opponents of the rule, titled “Protecting Statutory Conscience Rights in Health Care,” have said it is overly broad, granting refusal rights to workers who provide emergency services or those who are only tangentially involved in care, therefore endangering lifesaving health care for many patients, especially those from marginalized populations, and even encouraging such refusals. It could jeopardize the care of transgender people, of HIV-positive people, those taking PrEP, patients seeking abortion or contraception, and more. Clinics and hospitals that do not comply with the rule would stand to lose federal funding. Opponents refer to it as the “Denial of Care Rule.”

“Had the rule been allowed to take effect, a hospital receptionist could have refused to schedule an appointment for a patient seeking gender-affirming care or an orderly could have refused to transfer a patient to the operating room for an emergency abortion,” according to a press release from the American Civil Liberties Union. The ACLU and its New York affiliate represented the National Family Planning and Reproductive Health Association in its suit.

Englemayer said the rule “was sufficiently shot through with glaring legal defects,” according to Reuters, and that HHS had made a “demonstrably false” claim that there had been an increase in complaints from health care workers about conscience violations. He called the rule “a classic solution in search of a problem.”

The decision is likely to be appealed, although an HHS spokesperson offered no comment on the matter today, saying that HHS and the Department of Justice were reviewing the ruling.

LGBTQ and other civil rights groups were celebrating. “Today’s decision is an important victory against the Trump administration’s cruel and unlawful attempts to roll back critical patient protections,” Alexa Kolbi-Molinas, senior staff attorney with the Reproductive Freedom Project at the ACLU, said in a press release. “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.”

“In his decision to completely eliminate the Denial of Care Rule, Judge Paul A. Engelmayer has likely saved countless lives,” said a statement issued by Lambda Legal senior attorney Jamie Gliksberg. “Courts across the country are seeing the Denial of Care Rule for what it is, an egregious violation of the civil rights of and a direct attack on the lives of women, LGBT people, religious minorities and many others. The Denial of Care Rule was deeply rooted in animus against some of our most marginalized and vulnerable communities, and that has no place in our society. We are thrilled about today’s decision.” Lambda Legal is involved in the California case.

“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 the Rev. 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 is not the Trump administration’s last attack on services for marginalized populations, though. Last week it announced plans to allow organizations receiving HHS grants for adoption and foster care placement, homeless shelters, HIV services, and more to discriminate against clients who offend their religious beliefs. The administration also wants to eliminate provisions of the Affordable Care Act that ban anti-transgender discrimination.