Are there credible versions of Islam that are compatible with liberal democracy as it has developed in the west? Can one be both a good Muslim and a good citizen of a free society? Or are Islam and the post-Enlightenment west like fire and water?

While I have been in Egypt over the last fortnight, exploring these issues with Muslims and non-Muslims in a pivotal society of the Middle East, a debate has been bubbling away on the web (see www.signandsight.com) in which various woolly and nefarious views on the subject have been attributed to me. Among the accusations is that I, who was so much engaged for dissidents under communism, show insufficient solidarity with the "dissidents of Islam" such as Ayaan Hirsi Ali. This charge is based on a misunderstanding of the principle of solidarity which prevailed in the struggle against communism and should do so now. That principle is: total solidarity in the defence of people unjustly persecuted, total freedom to disagree with their views.

Our solidarity is particularly important in the case of people like Ayaan Hirsi Ali, who are not so much dissidents of Islam as dissidents beyond Islam. For as she recounts in her new autobiography, Infidel, she made a long hard journey to the point where she stood in front of the mirror in a Greek hotel room and said out loud, in Somali, "I don't believe in God". So she speaks as an atheist - and lives in daily peril of being murdered by jihadist fanatics as a result. One reason solidarity is so important in such cases is that attitudes to apostasy are a critical test for Muslim attitudes to freedom altogether. Last week, I pressed leading members of the Muslim Brotherhood in Cairo on precisely this issue. Their equivocal answers were not reassuring.

I cannot say plainly enough that anyone must be free not just to leave or change their religion but to propagate their new views, whether atheist, Christian, Muslim, Baha'i or whatever. In the course of those debates they have the right (though not the duty) to cause offence, without being intimidated by any laws, police harassment or threats of extremist violence. I have said this many times already and I repeat it here. We must defend this freedom unflinchingly. But it does not follow that one must agree with all the persecuted person's views. As it happens, I think Hirsi Ali is almost certainly right about God. And she's definitely right about the shameful, unacceptable oppression of women in some Muslim families and communities in Europe. But I don't think she's right about Islam.

"Islam," she told the Frankfurter Allgemeine Zeitung last year, "is not compatible with the liberal society that has resulted from the Enlightenment." Many western secular intellectuals participating in these debates agree. But some Muslim intellectuals disagree. I think we should listen to them carefully. Apart from anything else, when it comes to discussing Islam they know what they're talking about.

Take Gamal al-Banna, for example, whom I visited in Cairo, in a cavernous, dark apartment lined from floor to ceiling with Islamic literature. He is the younger brother of Hassan al-Banna, the founder of the Muslim Brotherhood. Their father, a learned imam, spent 40 years cataloguing some 45,000 reports of alleged sayings and doings of Muhammad (hadith). Now 86 years old, Gamal al-Banna has devoted his whole life to studying Islam and its relations to politics. A man of tranquil clarity, he became mildly agitated only when denouncing the perversion of Islam by Sayyid Qutb, the Egyptian apostle of extremist, takfiri Islamism and a hero to al-Qaida.

Gamal al-Banna argues that "there is no contradiction between total freedom of thought and religion" and that "Islam does not pretend to a monopoly of wisdom". Critical ideas about Islam should be fought "by words and not by confrontation, terrorism or takfir - passing anathema on someone by pronouncing them an infidel". As for apostasy, "the Muslim has the right to withdraw from Islam, the verses of the Qur'an are very explicit concerning this issue: 'There is no compulsion in religion' (al-Baqara, The Cow, II, 256). Withdrawal from religion is mentioned at least five times in the Qur'an, none of which is related to a penalty. In the period of the prophet, many people withdrew from Islam; one of them was a scribe of the Qur'an. The prophet did not punish any of them."

The saying often attributed to the prophet - "Whoever changes his religion must be executed" - is rejected as inauthentic by Imam Muslim, one of the earliest and most respected compilers of collections of hadith, but Imam al-Bukhari, another respected compiler, included it in his version. "The signs of falsification are very clear in this saying," comments Banna, "and it contradicts many verses in the Qur'an that confirm freedom of faith."

Compare this with Hirsi Ali's bold, bald statement in a speech in Berlin last year: "I think that the prophet Muhammad was wrong to have said that apostates must be killed." Which do you think reveals a deeper historical knowledge of Islam? Which is more likely to encourage thoughtful Muslims in the view that they can be both good Muslims and good citizens of free societies?

I'm not suggesting that we must choose only one or the other approach. We should listen to and support the dissidents beyond Islam, ex-Muslims like Hirsi Ali, but also the dissidents within Islam like Banna. He and other dissident Muslim intellectuals, such as Mohsen Kadivar in Tehran - their names scarcely known in the west - dissent from diverse conservative, state-sponsored and takfiri extremist positions, while remaining very much believing Muslims. For Islam exists as a monolith only in the imagination of the west. (And, one should add, in the western-influenced political dreams of some revolutionary Islamists). In fact, what has characterised the Muslim world throughout history is the great diversity of what Muslims say and do under the banner of Islam.

These dissidents within Islam are a small minority. So are the takfiri extremists who indoctrinate suicide-bombers. However, both these minorities have the capacity to appeal to larger numbers among the majority in between them - and especially to Muslims living in the west. So the voice of the dissidents needs to be heard more clearly. This struggle for Muslim hearts and minds should be decided by Muslims arguing among themselves, but we non-Muslims undoubtedly shape the context - and control many of the media - in which it is conducted.

The default position of some of the western secular intellectuals engaged in the current debate appears to be: the only good Muslim is an ex-Muslim. That is both patronising and counter-productive. It involves a simplistic parody of the real diversity of Islam. Of course we non-Muslims should try to make up our own minds about the nature of Islam, with the limited means at our disposal. But nothing could be more ludicrous and stupid than the western secular intellectual, having no Arabic and scant knowledge of Islamic history, philosophy or law, pronouncing confidently that Gamal al-Banna is a less true representative of Islam than Sayyid Qutb or Osama bin Laden. And stupid we should not be, if we wish to stay free.

www.timothygartonash.com