The Supreme Court ruled Wednesday that the Trump administration may allow employers and universities to opt out of the Affordable Care Act requirement to provide contraceptive care because of religious or moral objections.

The issue has been at the heart of an intense legal battle for nine years — first with the Obama administration sparring with religious organizations who said offering contraceptive care to their employees violated their beliefs, and then with the Trump administration broadening an exemption, angering women’s groups, health organizations and Democratic-led states.

Wednesday’s decision greatly expands the ability of employers to claim the exception, and the government estimates that between 70,000 and 126,000 women could lose access to cost-free birth control as a result.

The decision was one of several that has made the Supreme Court’s term strikingly successful for religious interests. By the same 7-to-2 vote as in the contraceptive cases, the court on Wednesday also ruled for the ability of religious organizations to hire and fire without offending some anti-discrimination laws.

And last week religious groups achieved a longtime goal when the court ruled that states that provide support to private education must allow religious schools to participate.

“It’s a big term,” said Mark Rienzi, president of the Becket Fund for Religious Liberty. And Wednesday’s decisions showed that “broad agreement for religious interests and religious diversity.”

The Supreme Court’s decisions will conclude Thursday with what could be a blockbuster decision abut whether President Trump may shield his private financial records and tax returns from congressional committees and a New York prosecutor.

It will be a fitting finale to a term in which the court has left few politically controversial topics untouched: It said federal law protects LGBTQ workers from discrimination, disappointed antiabortion activists and gun rights supporters, and stopped the Trump administration from ending the program that protects undocumented immigrants brought to the United States as children.

The contraceptive case involves a long-running dispute over Obamacare, as the ACA is known, and a requirement that employers provide cost-free birth control for female employees. The law itself doesn’t specify the rules, leaving it to federal agencies to determine how contraceptives fit into the mandate for cost-free “preventive care and screenings.”

The Obama administration required contraceptives and had narrower exceptions for churches and other houses of worship. It created a system of “accommodations,” or workarounds, for religiously affiliated organizations such as hospitals and universities. Those accommodations would provide the contraceptive care but avoid having the objecting organizations directly cover the cost.

The Trump administration moved in 2018 to expand the types of organizations that could opt out to include religious groups and nonreligious employers with moral and religious objections.

Under the rules, the employers able to opt out include essentially all nongovernmental workplaces, from small businesses to Fortune 500 companies. And the employer has the choice of whether to permit the workaround. (Most companies are happy to provide birth control.)

The U.S. Court of Appeals for the 3rd Circuit had put the Trump administration exemptions on hold, and said the agencies didn’t have the broad authority to grant them.

Justice Clarence Thomas, who wrote the majority opinion, said that was wrong.

“We hold that the [administration] had the authority to provide exemptions from the regulatory contraceptive requirements for employers with religious and conscientious objections,” wrote Thomas, who was joined by Chief Justice John G. Roberts Jr. and Justices Samuel A. Alito Jr., Neil M. Gorsuch and Brett M. Kavanaugh.

Thomas reasoned that if an administration’s agencies have “virtually unbridled discretion to decide what counts as preventive care and screenings, he said, they must also have “the ability to identify and create exemptions” from those guidelines.

Liberal Justices Elena Kagan and Stephen G. Breyer agreed with the court’s conservatives that the administration had the right to create an exemption, but they said lower courts should examine whether the administration’s rules were “consistent with reasoned judgment.”

Justice Ruth Bader Ginsburg issued a blistering dissent, in which she said her colleagues had gone too far to appease religious conservatives.

Until now, “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 in a brief joined by Justice Sonia Sotomayor.

“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.”

Ginsburg said Congress meant to provide “gainfully employed women comprehensive, seamless, no-cost insurance coverage for preventive care protective of their health and wellbeing.”

The court’s action, she wrote, “leaves women workers to fend for themselves, to seek contraceptive coverage from sources other than their employer’s insurer, and, absent another available source of funding, to pay for contraceptive services out of their own pockets.”

Thomas countered that it was Congress that left the decisions up to federal agencies. “Contrary to the dissent’s protestations, it was Congress, not the departments, that declined to expressly require contraceptive coverage in the ACA itself.”

Reproductive rights groups were alarmed by the decision.

“The Supreme Court’s decision to allow the Trump administration to put control over people’s birth control in the hands of the whims of their bosses and employers is deplorable,” NARAL Pro-Choice America President Ilyse Hogue said in a statement. “This decision just further exposes that ultimately, the Radical Right is really about controlling women and our lives with no eye towards equality or public health and well being.”

Religious groups said the legal battles should stop.

In addition to the Trump administration, the Little Sisters of the Poor defended the rules. The order of nuns, which runs homes for the elderly and employs about 2,700 people, pointed out that the government provided exemptions from the beginning for religious organizations such as churches. It said the accommodation provision violates the 1993 Religious Freedom Restoration Act, the law that says the government must have a compelling reason for programs that substantially burden religious beliefs.

“We are overjoyed that, once again, the Supreme Court has protected our right to serve the elderly without violating our faith,” said Mother Loraine Marie Maguire of the Little Sisters of the Poor, whose employees work in the group’s facilities. “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.”

White House press secretary Kayleigh McEnany said in a statement that the decision was “a big win for religious freedom and freedom of conscience.”

“Since Day One, the Trump Administration has sought to lift burdens on religious exercise for people of all faiths,” she said, adding the administration would work to allow “women who lack access to contraceptive coverage because of their employer’s religious beliefs or moral convictions to more easily access such care” through federal programs.

The states of Pennsylvania and New Jersey initially challenged the rules, noting that when women lose coverage from their employers, they seek state-funded programs and services.

While Thomas’s opinion leaned more heavily on administrative law than religious liberty, he praised the nuns who have been involved in challenging the mandate from the beginning.

“For over 150 years, the Little Sisters have engaged in faithful service and sacrifice, motivated by a religious calling to surrender all for the sake of their brother,” he wrote.

“. . . After two decisions from this court and multiple failed regulatory attempts, the federal government has arrived at a solution that exempts the Little Sisters from the source of their complicity-based concerns — the administratively imposed contraceptive mandate.”

But the legal fight might not be over.

In a concurring opinion, Alito and Gorsuch said the court had not gone far enough to settle the issue for good.

“We now send these cases back to the lower courts, where the Commonwealth of Pennsylvania and the State of New Jersey are all but certain to pursue their argument that the current rule is flawed on yet another ground,” Alito wrote.

He would have found that the religious exemption was not just authorized, but also required under the Religious Freedom Restoration Act.

“I would bring the Little Sisters’ legal odyssey to an end,” Alito wrote.

The cases are Little Sisters of the Poor v. Pennsylvania and Trump v. Pennsylvania.

Ann E. Marimow contributed to this report.