The Supreme Court late Friday rejected a California church’s challenge of the state’s new pandemic-related rules on worship services, with Chief Justice John G. Roberts Jr. joining the court’s liberals in the 5-to-4 vote.

Roberts wrote that state officials such as California Gov. Gavin Newsom (D) had leeway to impose restrictions to prevent the spread of coronavirus, and had not singled out places of worship for unfair treatment.

“The notion that it is ‘indisputably clear’ that the government’s limitations are unconstitutional seems quite improbable,” Roberts wrote. He was referring to the standard that challengers must meet to enjoin enforcement of the state order.

Justices Ruth Bader Ginsburg, Stephen G. Breyer, Sonia Sotomayor and Elena Kagan also voted to deny the request for intervention from a Pentecostal church near San Diego but did not join the statement by Roberts.

The court’s four most-consistent conservatives said they would have granted the request because the state’s new rules likely violate the Constitution’s protection of the free exercise of religion.

“California’s latest safety guidelines discriminate against places of worship and in favor of comparable secular businesses,” wrote Justice Brett M. Kavanaugh. “Such discrimination violates the First Amendment.”

Justices Clarence Thomas and Neil M. Gorsuch joined Kavanaugh’s dissent. The court’s order said Justice Samuel A. Alito Jr. also would have granted the church’s request, but he did not join the Kavanaugh statement.

Religious organizations eager to reopen faster and with fewer pandemic-related restrictions have been asking courts to step in, but this was the first case to reach the Supreme Court.

In a separate, less-controversial case from Illinois, the court without noted dissent turned down a request from churches near Chicago.

In both states, governors have recently removed some restrictions and agreed to requests that in-person worship services be allowed on Sunday, the Christian holy day of Pentecost.

The larger issue is how the responsibility of governments to control the spread of the novel coronavirus can be applied to churches, synagogues and mosques, and the constitutionally protected right to worship.

Last week, President Trump called on governors across the country to allow for the immediate reopening of places of worship, characterizing them as “essential services.”

Although all states are moving to ease restrictions, the Becket Fund for Religious Liberty says 21 still impose some restrictions.

But that is a moving target, as the litigation at the Supreme Court shows. Since South Bay Pentecostal Church near San Diego and Elim Romanian Pentecostal Church and Logos Baptist Ministries near Chicago filed their petitions, the governors of California and Illinois have eased restrictions.

Illinois Gov. Jay Pritzker (D) has removed the state’s ban on gatherings of more than 10 people, and California’s Newsom said churches may hold services so long as they do not exceed 25 percent of the facility’s capacity or 100 people, whichever is smaller.

Limits on houses of worship raise constitutional questions, Roberts said, but California had not shown bias against them.

“Similar or more severe restrictions apply to comparable secular gatherings, including lectures, concerts, movie showings, spectator sports, and theatrical performances, where large groups of people gather in close proximity for extended periods of time,” the chief justice wrote.

And California’s order “exempts or treats more leniently only dissimilar activities, such as operating grocery stores, banks, and laundromats, in which people neither congregate in large groups nor remain in close proximity for extended periods.”

Roberts said it would be inappropriate for the court to grant emergency relief to the church at a time when “local officials are actively shaping their response to changing facts on the ground.”

He added: “The precise question of when restrictions on particular social activities should be lifted during the pandemic is a dynamic and fact-intensive matter subject to reasonable disagreement” but entrusted by the Constitution to elected officials closest to the situation.

“They should not be subject to second-guessing by an “unelected federal judiciary,” which lacks the background, competence, and expertise to assess public health and is not accountable to the people,” he wrote, quoting a court precedent.

Kavanaugh wrote that the state had imposed unequal restrictions.

“The basic constitutional problem is that comparable secular businesses are not subject to a 25% occupancy cap, including factories, offices, supermarkets, restaurants, retail stores, pharmacies, shopping malls, pet grooming shops, bookstores, florists, hair salons, and cannabis dispensaries,” he wrote.

That was the issue pushed by lawyers for South Bay Pentecostal.

“Only one industry has a 25% capacity or 100-person cap — houses of worship,” said the church’s legal brief. “If California’s interest in limiting gatherings is not important enough to be enforced against other industries, it is not important enough to be enforced against churches.”

A panel of the U.S. Court of Appeals for the 9th Circuit, by a 2-to-1 vote, denied the church’s petition.

“We’re dealing here with a highly contagious and often fatal disease for which there presently is no known cure,” the court said. “In the words of Justice Robert Jackson, if a ‘court does not temper its doctrinaire logic with a little practical wisdom, it will convert the constitutional Bill of Rights into a suicide pact.’ ”

Judge Daniel P. Collins dissented, saying California’s plan was not neutral.

Since the court’s decision, though, Newsom released the new guidance, allowing South Bay to open Sunday.

The state contends that there are good reasons, though, for extending restrictions. Its expert testified that there “have been multiple reports of sizable to large gatherings such as religious services, choir practices, funerals, and parties resulting in significant spread of COVID-19.”

Included: “a worship service in Sacramento tied to 71 COVID-19 cases; a choir practice in Seattle linked to 32 cases; a Kentucky church revival tied to 28 cases; and a religious service in South Korea where over 5,000 cases were traced back to a single infected individual in attendance.”

Still, California told the Supreme Court, it was showing the deference to religious freedom the Constitution requires.

“While in-person religious services are now permitted, many other activities that are most comparable in terms of COVID-transmission risk factors — concerts, lectures, theatrical performances, or choir practices, in which groups of people gather together for extended periods — continue to be barred,” the state’s lawyers wrote.