A Saudi court has commuted the death sentence against a Palestinian poet convicted of apostasy, to eight years’ jail and 800 lashes, his lawyer said.

Ashraf Fayadh was detained by the religious police in 2013.

His conviction was based on evidence from a prosecution witness who claimed to have heard him cursing God, Islam’s Prophet Mohammad and Saudi Arabia. He was also prosecuted for the contents of a poetry book he had written years earlier.

Rights campaigners say he was targeted for speaking out on political and social matters.

Fayadh’s lawyer, Abdul-Rahman al-Lahim, said that while the new court ruling had commuted the execution, it had reconfirmed Fayadh’s guilt for the crime of abandoning his Islamic faith.

“The accused is sentenced to a punishment of eight years in jail and 800 lashes divided into instalments, 50 lashes for each instalment,” the ruling said, according to al-Lahim on a Twitter posting.

A spokesman for Saudi Arabia’s justice ministry could not be reached for comment.

Fayadh had initially been sentenced to four years in prison and 800 lashes but an appeal process led to that being increased to death after a judge ruled that defence witnesses’ testimony was ineligible.

Saudi Arabia’s justice system is based on Sharia, or Islamic law, and its judges are clerics from the ultra-conservative Wahhabi school of Sunni Islam. In the Wahhabi interpretation of sharia, religious crimes including blasphemy and apostasy incur the death penalty.

After a case has been heard by lower courts, appeals courts and the supreme court, a convicted defendant can be pardoned by King Salman.