WASHINGTON — In a 5-4 vote the Supreme Court late Wednesday barred restrictions on religious services in New York that the governor there imposed during the coronavirus.

The justices split, with new Justice Amy Coney Barrett in the majority and Chief Justice John Roberts dissenting. The vote just before midnight was a change for the court that earlier this year, when Justice Ruth Bader Ginsburg was present, divided 5-4 to leave in place pandemic-related capacity restrictions affecting churches in California and Nevada.

The majority said Gov. Andrew M. Cuomo ‘s orders violated the First Amendment’s protection of the free exercise of religion. And in a concurring opinion, Justice Neil M. Gorsuch said the governor treated some activities more favorably than others.

“It is time — past time — to make plain that, while the pandemic poses many grave challenges, there is no world in which the Constitution tolerates color-coded executive edicts that reopen liquor stores and bike shops but shutter churches, synagogues and mosques,” Gorsuch wrote.

The court’s action Wednesday could push New York to reevaluate its restrictions on houses of worship in areas designated virus hot spots. 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.

Agudath Israel of America, a 98-year-old Orthodox Jewish umbrella group headquartered in New York City, was represented by Becket and Troutman Pepper, asking the Supreme Court for emergency protection on behalf of Agudath Israel and affiliated synagogues as part of the ongoing lawsuit. The Catholic Diocese of Brooklyn brought a parallel case challenging the restrictions.

“Governor Cuomo should have known that openly targeting Jews for a special COVID crackdown was never going to be constitutional,” said Eric Rassbach, vice president and senior counsel at Becket and counsel to he plaintiffs.

“But treating synagogues and churches worse than the pet stores, liquor stores, and department stores also just didn’t make any sense, particularly when Agudath synagogues and Brooklyn parishes have carefully and responsibly followed the rules. The Supreme Court was right to step in and allow Jews and Catholics to worship as they have for centuries.”

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 Roman Catholic Church and Orthodox Jewish synagogues that had sued to challenge state restrictions announced by 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% 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% 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.

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.

The Associated press contributed to this report