The two men had often visited each other’s homes, and Mr. Homeidani, an officer in the National Guard, had a wife and six children who lost their breadwinner. Both men were also from prominent tribes, raising the specter of revenge killings if the slain man’s kin did not feel that justice had been served.

“We have nothing but the rule of Shariah,” said the victim’s brother, Faleh al-Homeidani. That meant the public beheading of Mr. Yehiya.

Since Mr. Yehiya’s life was at stake, his case took a path through the courts established for harsh punishments. A three-judge panel convicted him of murder, prompting an appeal to a five-judge panel, which affirmed the ruling and passed it to five judges on the high court.

If a majority of the judges at any level had doubted his guilt, the execution would have been stayed. But none did, so the case went to the royal court for a final review before the king could sign the execution order.

Mr. Yehiya was sentenced to death as retribution, meaning that only the victim’s heirs could pardon him. But he was spared immediate death because every one of the heirs must agree, and the victim’s youngest son was only 3, making him years short of the legal age for consent, which is 15. So Mr. Yehiya went to prison to wait for the boy to grow up before he could agree to have his father’s killer’s head cut off.

Many Muslims believe that saving a life, even that of a murderer, earns one rewards in heaven, so the possibility of a pardon by the victims’ heirs has opened a realm of activism aimed at stopping executions.

After Mr. Yehiya’s conviction, his family campaigned on his behalf, and he became a religious leader in prison, earning the respect of clerics, who took up his cause. Much of the job fell to Sheikh Rashid al-Shalash, a wide-eyed, chatty cleric who heads a committee in Qassim Province that campaigns for pardons.