The Supreme Court ruled unanimously on Monday that faith-based nonprofits can be treated the same as churches under federal retirement laws, in a decision signaling broad deference to religious institutions.

Houses of worship are allowed greater freedom to structure their retirement plans than most corporations under the Employee Retirement Security Act (ERISA), but it was unclear whether religiously affiliated nonprofits such as parochial schools and church-run hospitals would be afforded the same flexibility.

In an 8-0 ruling, the high court said Congress, in a 1980 amendment to the law, did intend for religious nonprofits to be considered a “church plan,” making them exempt from some of ERISA’s strict requirements.

“The question presented here is whether a church must have originally established such a plan for it to so qualify. ERISA, we hold, does not impose that requirement,” Justice Elena Kagan wrote in the court’s opinion.

Analysts had been watching the case to see if it would give a hint as to how the court sees another legal battle involving religiously affiliated nonprofits: the Obamacare contraceptive mandate. In that case, houses of worship don’t have to purchase insurance plans that cover contraceptives, but charities do.

Some high-profile nonprofits such as the Little Sisters of the Poor, an order of Catholic nuns, have sued, arguing requiring them to be involved in any way with their employees obtaining contraceptives violates their religious beliefs.

The justices have sent the contraceptive case back to lower courts to sort out, looking for an accommodation both sides can live with.

Monday’s retirement ruling was narrow and based on ERISA, but analysts said it did signal a deference to churches that could affect future religious liberty cases.

“It’s fair to say that the court’s approach to interpreting the statute is one which is favorable to religious organizations and could help in other kinds of cases where an interpretation of regulations or statute may be required,” said Stuart Lark, a partner at Sherman & Howard.

Monday’s ruling overturns an appeals court decision that had sided with employees and against Advocate Health Care Network, a church-affiliated operation.

Justice Kagan said in her ruling that the government needed to be careful about inserting itself into decisions of faith.

“A church-establishment requirement necessarily puts the IRS in the business of deciding just what a church is and is not,” she wrote.

She cited the late Justice Antonin Scalia’s book, “Reading Law: The Interpretation of Legal Texts,” in saying judges needed to defer to the way Congress wrote the law.

Jordan Lorence, an attorney at Alliance Defending Freedom, said Justice Kagan’s opinion shows “the textualist approach is very strong and alive at the Supreme Court.”

“It grants a very broad view of church autonomy, which I think is great,” he said. “It pushes back government regulation of internal church affairs.”

Mayor Brown, one of the nation’s largest law firms, said the ruling saved religiously affiliated hospitals from serious compliance costs.

“The hospitals at issue in the case decided today would have faced a $4 billion shortfall in funding the pensions of 300,000 workers if the Court had ruled differently,” the law firm said in a statement.

Justice Sonia Sotomayor, while ultimately agreeing with her fellow justices’ read of the law, signaled she was uncomfortable with the implications.

Despite having a relationship with churches, nonprofits — like the hospitals in this case — operate for-profit subsidiaries that earn billions of dollars and employ thousands of people, Justice Sotomayor argued.

“These organizations thus bear little resemblance to those Congress considered when enacting the 1980 amendment to the church plan definition. This current reality might prompt Congress to take a different path,” Justice Sotomayor wrote in her concurrence.