When Alex Aan picked up a copy of Karen Armstrong's Holy War from his local library in west Sumatra in 2005, he had little inkling of his own religious battle to come. But after posting "God doesn't exist" on Facebook, the soft-spoken civil servant, 30, faces up to 11 years in jail for what is considered blasphemy in Indonesia.

His case has stoked a debate in the world's most populous Muslim nation, whose 240 million citizens are technically guaranteed freedom of religion but protected by law only if they believe in one of six credos: Islam, Catholicism, Protestantism, Buddhism, Confucianism and Hinduism. Those who question any of those face five years in prison for "insulting a major religion", plus an additional six years if they use the internet to spread such "blasphemy" to others.

Activists say Aan's is the first case in which an atheist is being tried in relation to the first pillar of Indonesia's state philosophy – pancasila, which requires belief in one god. From the medium-security rural prison where he has been held for the past two months, Aan has little hope for the future. He has been beaten by angry mobs, rejected by his community and endured public calls for his beheading. For now he is lying low in his cramped cell, awaiting an imminent verdict and has told none of his fellow inmates about his supposed crime.

"The truth is way too dangerous," says Aan quietly, his hands clasped together over his prison-issue blue jeans and button-down shirt. "I'm really worried about my future. And I'm only just now starting to think about how I'm going to deal with it."

Authorities moved Aan from his local prison in west Sumatra's capital, Padang, after he was badly beaten by a group of inmates who knew his case. To see their client for 15 minutes, Aan's lawyers must drive for four hours along a treacherous mountain road that bisects the dwindling Sumatran rainforest and crisscrosses valleys until it ends in a cul-de-sac at the prison's gates.

Aan's counsel, a ragtag team of young smokers in T-shirts and sandals, don't expect justice. "What Alex has 'done' is exercise freedom of expression," says Taufik Fajrin, one of the five lawyers defending him pro bono. "We'll try our best to get him freed but just hope he'll get a minimum sentence. Promoting human rights here is hard because you face fanatics and hardline culturalists. Even we, as his lawyers, are worried that hardliners will come to our office or homes and throw stones at us. It's a challenge."

While his lawyers estimate there may be up to 2,000 atheists in Indonesia, "there's no real way of knowing", Fajrin says. The repercussions are too dangerous.

According to Andreas Harsono, a local human rights activist, Aan's case is just one of a growing number of examples of religious intolerance across Indonesia, ranging from harassment to mob and arson attacks against groups such as the Baha'i, Shia and Ahmadiyah Muslims – sometimes ending in death.

Last year, the local Setara Institute for Democracy and Peace recorded 244 acts of violence against religious minorities – nearly double the 2007 figure.

Activists argue that the country is increasingly influenced politically and financially by conservative Wahhabi clerics from the Middle East, particularly Saudi Arabia, who help to incite intolerance in Indonesia. But the country's discriminatory laws – ranging from vaguely worded decrees against proselytising to requirements to state one's religion on one's national identity card – as well as the increasing number of Muslim hardliners who have taken the law into their own hands, are also to blame, Harsono says.

"Victims keep getting longer prison terms and perpetrators less, while the human rights we set in place 10 years ago are becoming unravelled," he says. "We're seeing a motion to ban mini-skirts in government buildings whereas [before] it was OK. Beauty queen contests were OK'd in the 1970s but have been banned in some provinces, while Valentine's Day celebrations were given the green light 30 years ago but this year were banned in Aceh.

"The situation is getting crazy," Harsono continues. "We used to discuss these issues. Now there is no discussion. The discourse today is 'This is un-Islamic and immoral'."

Indonesia's Christians have suffered most, perhaps. The Indonesian Communion of Churches says about 80 churches have been closed each year since President Susilo Bambang Yudhoyono took power in 2004, and an additional 1,000 congregations have faced harassment.

For many of those who consider themselves defenders of Islamic culture, such as the Padang clan chief, Zainuddin Datuk Rajo Lenggang, religious minorities like Aan pose a serious threat to Indonesia's national identity – and atheists are particularly risky.

"If you are not a religious person, you might be dangerous to others, behaving without control and doing anything you like," Lenggang says. "Religion brings order. You cannot be an individualist."

Although Aan has issued a public apology for his Facebook message and has since converted to Islam, the hardline Islamic Society Forum has called for the use of the death penalty in his case, and Lenggang says it is too late to be forgiven by his community: "Once you doubt the existence of Allah, you are kafir – you are no longer accepted. In the old days, he may be beaten until he died. But that could still happen today. This is about faith and people can be very strict."

Aan's parents paint a portrait of a devout and intelligent son who was always interested in logic, justice and truth, and also seemingly went to great pains to keep up appearances. "My son is not an atheist," says his mother, Nuraina, through tears. "Since his childhood, he has always been diligent, always praying in the mosque, five times a day."

Aan, who has the support of the US-based Atheist Alliance International and Council of ex-Muslims of Britain, says he knew from an early age that he was an atheist, but recognised that he would have to hide it from others. "From 11, I thought 'If God exists, why is there suffering? Why is there war, poverty, hell?' Because, to me, God would not create this hell. My family would ask me my thoughts but I knew my answers would cause problems, so I kept quiet."

He looks out the window to where a group of inmates are celebrating their Sunday by performing karoake to drum'n'bass in the dusty prison yard, most of them smoking, all of them barefoot. "I only want to see a better world and help create a better world," he says. "If I cannot … then I would prefer to die."