A relative of the Jordanian writer Nahed Hattar joins a sit-in near Amman, Jordan, after his killing. (Muhammad Hamed/Reuters)

A well-known Jordanian writer and political activist was fatally shot Sunday morning as he headed into a courtroom in Amman to face charges over a cartoon he shared on his Facebook page that some deemed offensive to Islam.

The writer, 56-year-old Nahed Hattar, was hit by three bullets on the steps of the courthouse in a prominent business and residential district in Amman, the capital, according to Petra, the state-run news agency.

A witness told the Associated Press that the shooter was “wearing a long gray robe and long beard characteristic of conservative Muslims.” The assailant was caught by Hattar’s family and turned over to police, who have not released the shooter’s identity.

Hattar, a secular Christian, was arrested in August for sharing a cartoon on his Facebook page titled “the God of Daesh,” an alternative name for the Islamic State militant group. The creator of the cartoon is unknown.

The drawing showed a bearded man, lying in bed under sheets, smoking contentedly beside two women in paradise and jabbing his finger toward God, who asks, “Do you need anything?” The man replies, “Yes, Lord, bring me wine, cashews and an immortal servant to come clean the floor.”

Hattar took the image down and tried to explain why he posted it. He said the cartoon was a depiction of the perverted beliefs of Islamic State militants and mocked “how they imagine God and heaven, and does not insult God in any way.”

Some Muslims and the Jordanian government were nevertheless offended by the cartoon, in part because it depicted God.

Hattar was arrested and spent two weeks in jail before being freed on bail. He was charged with inciting sectarian strife and insulting Islam. He was headed to court Sunday for a hearing.

Hattar’s relatives accused the government, including the prime minister and interior minister, of failing to protect the writer and of inciting the public against him. Jordan is ruled by King Abdullah II, a close ally of the United States, and it is a member of the coalition that has been mounting aerial attacks against the Islamic State in Syria and Iraq.

In a statement, translated by the BBC, the Hattar family charged that “many fanatics wrote on social media calling for his killing and lynching, and the government did nothing against them.”

Jordanian groups associated with the Muslim Brotherhood, a conservative pro-Islamist force, condemned the killing of Hattar.

Hattar has been arrested before, for insulting the monarch. He is also a strong supporter of Syrian President Bashar al-Assad, according to a report by Reuters.