The Supreme Court said Alabama could not execute a death row inmate without the man’s pastor by his side and indicated that other states must find a way to honor final requests for a spiritual adviser in the death chamber.

The court’s order came an hour before Alabama’s self-imposed Thursday night deadline of executing Willie B. Smith III, convicted of a 1991 robbery and murder. A lower court had put the execution on hold, and Alabama asked the Supreme Court to step in.

But the request divided the court’s conservative majority. For the first time since she joined the court in October, Justice Amy Coney Barrett sided with liberal colleagues in a capital punishment case, saying federal law requires states to make accommodations for prisoners like Smith.

Barrett joined an opinion by Justice Elena Kagan that said a federal law protecting the religious rights of prisoners set a high bar Alabama did not meet.

“Alabama has not carried its burden of showing that the exclusion of all clergy members from the execution chamber is necessary to ensure prison security,” Kagan wrote. “So the state cannot now execute Smith without his pastor present, to ease what Smith calls the ‘transition between the worlds of the living and the dead.’ ”

Kagan’s opinion was also joined by fellow liberals Stephen G. Breyer and Sonia Sotomayor.

The court’s midnight order did not state how every member of the court voted. But either conservative Justices Samuel A. Alito Jr. or Neil M. Gorsuch — or both — must have agreed with the outcome to make up a majority.

Justice Clarence Thomas, without additional comment, said he would have allowed the execution to proceed.

Justice Brett M. Kavanaugh and Chief Justice John G. Roberts Jr. said they would have as well, because Alabama’s ban is nondiscriminatory and, in Kavanaugh’s words, “serves the State’s compelling interests in ensuring the safety, security and solemnity of the execution room.”

But he added that the rest of the court did not agree, and other death-penalty states should take heed.

States wanting to avoid months or years of litigation, Kavanaugh wrote, “should figure out a way to allow spiritual advisors into the execution room, as other States and the Federal Government have done. Doing so not only would satisfy inmates’ requests, but also would avoid still further delays and bring long overdue closure for victims’ families.”

Alabama Attorney General Steve Marshall declined to comment through a spokesman. Smith’s execution will probably be postponed at least a month.

One of Smith’s attorneys, Anand Agneshwar, said states should not be resistant.

“The issue really comes up only when somebody makes a sincere request for this accommodation,” Agneshwar said. “It’s hard to see how states can come up with a good reason not to allow it,” especially since it is allowed in federal executions.

The Alabama case has a backstory that has bitterly cleaved the court.

In 2019, it split 5 to 4 to allow Alabama’s execution of a Muslim inmate, Domineque Ray, although he protested that the state only allowed a state-employed Christian chaplain to accompany inmates in their final moments before execution.

Some conservatives in the majority later said it was because Ray had filed his complaint too late. But the order drew fire from both the left and religious conservatives on the right.

Kagan wrote a stinging dissent in the case, saying “Ray has put forward a powerful claim that his religious rights will be violated at the moment the state puts him to death.”

A couple of months later, the court stopped an execution in Texas because the state said it could not accommodate a Buddhist inmate’s request for a spiritual adviser to be with him in the death chamber.

At the time, Texas allowed only Christian and Muslim chaplains to attend executions. Kavanaugh wrote that the government “may not discriminate against religion generally or against particular religious denominations.”

But he said states could solve the problem by excluding all outsiders from the death chamber.

Alabama changed its policy as a result. But Smith said that did not satisfy a federal law protecting the rights of inmates — the Religious Land Use and Institutionalized Persons Act — and a panel of the U.S. Court of Appeals for the 11th Circuit agreed.

Kagan said the lower court was right and Alabama’s defense that it was concerned about security did not hold up; until the recent change, it required chaplains to be present, she noted.

“Alabama’s policy substantially burdens Smith’s exercise of religion” and leaves inmates “to die without spiritual attendance,” Kagan wrote.

Quoting from Smith’s complaint, she added “Smith understands his minister’s presence as ‘integral to [his] faith’ and ‘essential to [his] spiritual search for redemption.’ His pastor, Smith says, will not only ‘relieve his struggle as he passes,’ but also help him ‘properly express to God his repentance.’ ”

Smith was scheduled to receive a lethal injection at a south Alabama prison for the decades-old murder of 22-year-old Sharma Ruth Johnson in Birmingham.

Smith, along with others, abducted Johnson at gunpoint from an ATM. They later used her card to steal $80 from her account and then took her to a cemetery, where Smith shot her in the back of the head.

The justices vacated another stay issued by the 11th Circuit related to Smith’s intellectual capacity and a challenge to the method of execution.

Barrett’s role in capital punishment cases has been closely watched not only because of the impact a new justice can make, but also because of past comments about her Catholic faith and capital punishment.

In 1998, she co-wrote a law review article titled “Catholic Judges in Capital Cases” that described the tensions. She suggested judges who felt they could not be impartial because of their faith should recuse and wrote, “Catholic judges (if they are faithful to the teaching of their church) are morally precluded from enforcing the death penalty.”

As a nominee for the U.S. Court of Appeals for the 7th Circuit and later the Supreme Court, Barrett said she would be reluctant to enter an order of execution if she were a trial judge, but it was different for appellate judges considering issues of law in the case of someone already on death row.

Since she joined the high court, she has consistently voted with conservatives to deny stay requests from death row inmates as the Trump administration made a concerted effort to revive the federal death penalty. The federal government executed 13 people, which as Sotomayor noted in one dissent, is “three times as many people in the last six months than it had in the previous six decades.”

The Alabama case is Dunn v. Smith.