A federal court blocked the execution of a Muslim inmate sitting on death row on Wednesday after it ruled the state of Alabama violated his religious liberties under the Constitution for not allowing an imam to be present in the execution chamber.

The U.S. Court of Appeals for the 11th Circuit in Atlanta granted Dominique Ray, 42, a last-minute stay of execution on Wednesday, the day before he was scheduled to die by lethal injection for murdering and raping 15-year-old Tiffany Harville because Alabama refused Ray’s request to have an imam present in his execution chamber.

The federal appeals court overturned a Montgomery federal judge’s motion last week to deny a stay of execution.

“The central constitutional problem here is that the state has regularly placed a Christian cleric in the execution room to minister to the needs of Christian inmates, but has refused to provide the same benefit to a devout Muslim and all other non-Christians,” the judges wrote in their ruling.

Ray, who was slated to be executed at 6 p.m. CST on Thursday, converted to Islam during his time in prison and demanded that an imam accompany him to his execution.

Alabama law allows a spiritual adviser to witness the execution from a room adjacent to the execution chamber, but it does not allow the adviser to enter the execution chamber.

The state does, however, allow a Christian prison chaplain who is a salaried Department of Corrections employee to be present in the chamber to pray with the inmate at the inmate’s request.

Alabama prison officials say that they allow the prison chaplain in the execution chamber because the employee is trained to handle executions and be available to assist should something go wrong, the Montgomery Advertiser reported.

The state granted Ray’s request to bar the Christian prison chaplain from being present in the chamber.

Ray’s attorneys filed a challenge to the execution ruling last week, but a lower court denied the challenge, saying “the risk posed by allowing another cleric into the execution chamber” was too much for Alabama to handle.

But the appeals court argued that Alabama did not provide evidence that the imam was a security risk, adding that the state should be able to train the imam in proper prison protocol before the execution.

The Council on Islamic Relations (CAIR), the largest Muslim civil rights advocacy organization, announced Wednesday that it “welcomed” the appeals court’s ruling.

“We welcome this decision and hope Mr. Ray will ultimately be provided equal access to spiritual guidance,” said Ali Massoud, government affairs coordinator for CAIR-Alabama.

The Alabama Attorney General’s Office announced after the appeals court ruling that it would take the case to the Supreme Court, arguing that Ray’s execution should go on as planned.