Aan started an atheist group on Facebook on which he shared comic strips of the prophet, Dharma said.

He also uploaded three articles on his account written about the prophet.

“Under the Electronic Information and Transactions law, we sentence him to prison for a length of two years and six months,” Dharma said.

“What he did has caused anxiety to the community and tarnished Islam.”

Aan was beaten by an angry mob and arrested by police in his hometown of Pulau Punjung in western Sumatra in January after posting the material online and declaring himself an atheist.

The court had earlier indicted Aan with two other charges – persuading others to embrace atheism and blasphemy – and prosecutors had sought a three-and-a-half-year jail term for him.

But the court convicted him of the most serious charge and dropped the other two.

Aan’s arrest sparked outrage among Indonesians and international activists, who showed their support on his Facebook group and circulated petitions to have his charges dropped.

Indonesia, the world’s largest Muslim-majority nation, guarantees freedom of religion in its constitution and the International Covenant on Civil and Political Rights, but only recognises six faiths: Islam, Buddhism, Hinduism, Catholicism, Protestantism and Confucianism.

Its courts have in recent years given light sentences to perpetrators of violent attacks on Christians and Ahmadis, some of which have been fatal.