The U.S. Supreme Court on Wednesday upheld Trump administration regulations granting employers broad rights to deny their female workers no-cost coverage for birth control by citing religious and moral objections.

As a result, as many as 126,000 women could lose coverage for free birth control through workplace health plans in the first year, according to government estimates.

The 7-2 ruling overturned previous decisions by federal courts in Philadelphia, which had blocked the rules from taking effect.

Writing for the majority, Justice Clarence Thomas found that the administration had acted within its authority when it sought in 2017 to broaden existing exemptions to the “birth control mandate” implemented as part of President Barack Obama’s signature Affordable Care Act.

“For the past seven years,” Thomas wrote, objectors — including an order of Roman Catholic nuns who intervened in the case — “have had to fight for the ability to continue in their noble work without violating their sincerely held religious beliefs.”

Justices Ruth Bader Ginsburg and Sonia Sotomayor dissented sharply.

“In accommodating claims of religious freedom, this Court has taken a balanced approach, one that does not allow the religious beliefs of some to overwhelm the rights and interests of others who do not share those beliefs,” Ginsburg wrote. “Today, for the first time, the Court casts totally aside countervailing rights and interests in its zeal to secure religious rights to the nth degree.”

LISTEN: Justice Ruth Bader Ginsburg responds skeptically during oral arguments in May:

The case stemmed from a lawsuit brought by the attorneys general of Pennsylvania and New Jersey, who objected to President Donald Trump’s effort in 2017 to expand existing exemptions that allow churches and some closely held private businesses whose owners had religious objections to opt out of paying for birth control for their workers.

Under the new proposals, virtually all employers, ranging from small businesses to Fortune 500 companies, could cut off coverage as well.

A federal judge in Philadelphia blocked the new rules the day they were set to go into effect, finding that states would be saddled with the financial burden of paying for resulting unplanned pregnancies and the cost for women who turned to state agencies to cover their contraceptive needs. The U.S. Court of Appeals for the Third Circuit agreed last year.

But the Supreme Court’s ruling will send the case back for further review to the lower courts, where Pennsylvania Attorney General Josh Shapiro vowed Wednesday to continue to challenge the regulations on different legal grounds.

“This fight is not over,” he said in a statement, adding: “Nobody should get in between a woman and her doctor. No employer should deny their employees medicine based only on the employer’s personal beliefs.”

Trump, who has pegged his reelection chances on support from evangelical and other Christian voters, hailed the court’s decision as a victory.

Wednesday’s ruling, said White House spokesperson Kayleigh McEnany in a statement, “is a big win for religious freedom and freedom of conscience.”

Nearly 63 million women receive free birth control through employer plans and save $255 annually on average, according to the Kaiser Family Foundation.

The “birth control mandate” has been one of the most fiercely litigated aspects of Obamacare. And the case decided Wednesday marks the third time this small but hotly contested portion of the Affordable Care Act has drawn high court scrutiny.

All three times the justices considered cases arising out of Pennsylvania, a state that since the Supreme Court’s landmark abortion decision in Planned Parenthood v. Casey in 1992 has often found itself at the forefront of debates over reproductive rights.

Since it was enacted, the ACA has generally required employers and insurers to provide preventative health services to women at no charge. Houses of worship that claimed religious objection were provided an avenue to opt out soon after the law’s passage.

The swath of employers eligible for exemptions has gradually expanded in the decade since — and after a number of court battles — to include religiously affiliated hospitals, universities, and nonprofits.

In 2014 — in a case brought by a Lancaster County cabinetmaker alongside the crafting chain Hobby Lobby — the justices expanded exemptions to include businesses held by a small group of owners who object to the use of contraception on religious grounds.

The Obama administration countered with compromise regulations that required those companies to still provide health-care plans offering contraception but shifted the burden of paying for it from the employers to their insurers.

That prompted another challenge led by nonprofits associated with the Roman Catholic Diocese of Pittsburgh in 2015. They argued the new rules might let them off the hook financially but still required them to tacitly support the use of medicines that violated their beliefs. The Supreme Court deadlocked in a 4-4 split on that case, sending it back to the lower courts without a definitive ruling.

Since taking office, Trump has vowed to eliminate even that mandate in seeking to fulfill a campaign pledge he made to protect employers from being “bullied by the federal government because of their religious beliefs.”

Wednesday’s ruling is unlikely to settle the matter for good.

Sister Loraine Marie Maguire, mother provincial of the Little Sisters of the Poor, an order of Roman Catholic nuns who intervened in the latest suit, thanked the court for “protecting our right to serve the elderly without violating our faith.”

“Our life’s work and great joy is serving the elderly poor and we are so grateful that the contraceptive mandate will no longer steal our attention from our calling,” she said.

LISTEN: Lawyers for the Little Sisters of the Poor lay out their religious objections at oral arguments in May:

Shapiro, the Pennsylvania attorney general, took issue with Maguire’s characterization of the stakes.

“Our case was never about requiring religious groups to provide contraception — organizations like the Little Sisters are already exempt,” he said. “Our case is about an overly broad rule that allows the personal beliefs of CEOs to dictate women’s guaranteed access to contraceptive medicine.”