WASHINGTON, D.C. — As coronavirus cases surge again nationwide the Supreme Court late Wednesday barred New York from enforcing certain limits on attendance at churches and synagogues in areas designated as hard hit by the virus.

The justices split 5-4 with new Justice Amy Coney Barrett in the majority. It was the conservative’s first publicly discernible vote as a justice. The court’s three liberal justices and Chief Justice John Roberts dissented.

The move was a shift for the court. Earlier this year, when Barrett’s liberal predecessor, Justice Ruth Bader Ginsburg, was still on the court, the justices divided 5-4 to leave in place pandemic-related capacity restrictions affecting churches in California and Nevada.

The court’s action Wednesday could push New York to reevaluate its restrictions on houses of worship in areas designated virus hot spots. But the impact of the court’s action is also muted because the Catholic and Orthodox Jewish groups that sued to challenge the restrictions are no longer subject to them.

The Diocese of Brooklyn and Agudath Israel of America have churches and synagogues in areas of Brooklyn and Queens previously designated red and orange zones. In those red and orange zones, the state had capped attendance at houses of worship at 10 and 25 people, respectively. But the those particular areas are now designated as yellow zones with less restrictive rules neither group challenged.

The justices acted on an emergency basis, temporarily barring New York from enforcing the restrictions against the groups while their lawsuits continue. In an unsigned opinion the court said the restrictions “single out houses of worship for especially harsh treatment.”

“Members of this Court are not public health experts, and we should respect the judgment of those with special expertise and responsibility in this area. But even in a pandemic, the Constitution cannot be put away and forgotten. The restrictions at issue here, by effectively barring many from attending religious services, strike at the very heart of the First Amendment’s guarantee of religious liberty,” the opinion said.

The opinion noted that in red zones, while a synagogue or church cannot admit more than 10 people, businesses deemed “essential,” from grocery stores to pet shops, can remain open without capacity limits. And in orange zones, while synagogues and churches are capped at 25 people, “even non-essential businesses may decide for themselves how many persons to admit.”

Roberts, in dissent, wrote that there was “simply no need” for the court’s action. “None of the houses of worship identified in the applications is now subject to any fixed numerical restrictions,” he said, adding that New York’s 10 and 25 person caps “do seem unduly restrictive.”

“The Governor might reinstate the restrictions. But he also might not. And it is a significant matter to override determinations made by public health officials concerning what is necessary for public safety in the midst of a deadly pandemic,” he wrote.

Roberts and four other justices wrote separately to explain their views. Barrett did not.

The court’s action was a victory for the Catholic Church and Orthodox Jewish synagogues that had sued to challenge state restrictions announced by Gov. Andrew Cuomo on Oct. 6.

The Diocese of Brooklyn, which covers Brooklyn and Queens, argued houses of worship were being unfairly singled out by the governor’s executive order. The diocese argued it had previously operated safely by capping attendance at 25 percent of a building’s capacity and taking other measures. Parts of Brooklyn and Queens are now in yellow zones where attendance at houses of worship is capped at 50 percent of a building’s capacity, but the church is keeping attendance lower.

“We are extremely grateful that the Supreme Court has acted so swiftly and decisively to protect one of our most fundamental constitutional rights — the free exercise of religion,” said Randy Mastro, an attorney for the diocese, in a statement.

Avi Schick, an attorney for Agudath Israel of America, wrote in an email: “This is an historic victory. This landmark decision will ensure that religious practices and religious institutions will be protected from government edicts that do not treat religion with the respect demanded by the Constitution.”

Two lower courts had sided with New York in allowing the restrictions to remain in place. New York had argued that religious gatherings were being treated less restrictively than secular gatherings that carried the same infection risk, like concerts and theatrical performances. An email sent early Thursday by The Associated Press to the governor’s office seeking comment was not immediately returned.

There are currently several areas in New York designated orange zones but no red zones, according to a state website that tracks areas designated as hot spots.