Even during the most tense and dangerous days of recent times, Marrakesh, the tourist capital of Morocco, has remained a remarkably relaxed place. The chief dangers in this north African playground are a dodgy kebab from the street vendors in the main square of Jemaa-el-Fna, being hassled by "guides" in the medina, or bumping into the likes of Sting and Michael Portillo, who are among the many visitors who come here to stay in luxury hotels and indulge in western pleasures against the background of a thrillingly exotic and deeply alien setting.
This much fits perfectly with the image Morocco likes to present to the outside world, as the liberal and unthreatening face of Islam. And on the surface, there is not much to contradict this view. Although security at Casablanca airport has been mildly intensified in the wake of threats at Heathrow, there is still any number of western tourists - among them, on my last visit, a group of elderly birdwatchers from Yorkshire - who potter about harmlessly in the shops, mingling incongruously with returning pilgrims from Mecca, their bags clattering with duty-free fags and booze. At times, it is hard even to tell that you are in an Arab country. True, the airport bookstall stocks lavish copies of The Founding Myths of Israeli Politics by Roger Garaudy (a notoriously anti-Semitic book banned a few years ago in France) but, such details aside, you could be anywhere in the western world.
You don't have to be in Morocco long, however, to sense that all is not quite right here. In the past few weeks, the tension on the streets of Tangier, Casablanca and Rabat, the gritty and industrial main cities, has been palpable. This is partly because of the coming war with Iraq, which Moroccans fear and dread as much as any other people in the Arab world; and because Osama Bin Laden has recently targeted the country as "ready for liberation", meaning that Moroccans can expect an imminent al-Qaeda attack.
There are also long-simmering local hatreds that seem about to boil over. Morocco's hard-won stability is being threatened by a rising tide of Islamic fundamentalism, led by disparate but highly organised groups of "integristes". The biggest of these is the Party for Justice and Development (PJD) which, with 42 seats, commands third place in the Moroccan parliament. Far more important is the group al-'Adl wal-Ihsan (Justice and Spirituality, or Justice and Charity), estimated to have more than 30,000 members, which is led by Sheikh Abdessalam Yassine, a former mystic and charismatic preacher who is often claimed as the "Khomeini" of Morocco.
Yassine is based in Sale, an impoverished town just across the river from the capital, Rabat. Here, while refraining from openly advocating violence, he preaches that the government will fall when the Islamists reach a critical mass of four million.
To travel across the grubby estuary that separates Rabat from Sale is like crossing an invisible internal border. It is not just Sale's grime and poverty that are striking compared to Rabat - the contrast between glamour and wretchedness is a defining characteristic of the Moroccan experience - but also the wariness of the town's inhabitants and their obvious resentment of outsiders. Yet this is hardly surprising, as Sale is also home to Salafi Jihadi (Salafist Combat), whose leader, the dashing and ruthless Hassan Ben Ali Kettani, has been called the Moroccan Bin Laden by the press. Kettani, who has a sly smile of unparalleled nastiness, preaches in Sale at the Mosquee de La Mecque. This is an undistinguished building that became the local equivalent of the Finsbury Park Mosque in early 2002 when it was raided by Moroccan police with the aid of military helicopters. What they uncovered there has terrified Moroccans ever since.
Salafi Jihadi was founded in the early 1990s by 40 veterans of the Afghan wars; by 2002, it had 400 known members and was alleged to be providing logistical support to the al-Qaeda cell (consisting of Saudis) plotting attacks on the Straits of Gibraltar from Casablanca. Worse still, it was rumoured to have clear links with the shadowy death squad Takfir wal-Hijra (Judgement on the Infidels). Between them, the two groups are alleged to have been responsible for roughly 300 killings across Morocco.
In Nador, Rabat, Mohammedia, Casablanca and Sale, drug- dealers, drinkers, prostitutes, policemen and others suspected of non-Islamic behaviour have been thrown into wells, stoned to death, or had their throats cut. The police discovered that the Salafist remit was even wider than they had thought: in the formerly louche and sophisticated semi-European haven of Tangier, for example, one of Kettani's most trusted comrades, Mohammed Fezzazi, the local Salafist leader, controlled the city until recently with an iron fist. In nearby Tetouan, a wild border town in the Rif known mainly for drugs and people-smuggling, Omar Hadouchi, who along with the other Salafists cites Bin Laden as his inspiration, controls the spiritual and economic life of the poor quarters of town.
For most ordinary Moroccans, it is clear that something important is changing. The clearest demonstration of this assertion has been a frightening and unparalleled rise in violent crime in the central Casablanca districts of Maarif, Hay Hassani and Al Fida. In the cafes, taxis and buses, there are rumours of gangsterism, political score-settling and even vampirism. Matters have not been helped by reports in Rabat of bearded men with knives attacking westernised Moroccan women in the smart district of Agdal for not wearing the veil.
If, however, there is a fightback among ordinary Moroccans against the Islamist militants, it is taking place first of all on the cultural level. According to the novelist Youssouf Amine Elalamy, when I spoke to him in Rabat a few weeks ago, this is because contemporary Moroccan culture is fast-moving, sharp and sophisticated enough to negotiate the gap between east and west - the empty space currently occupied by the Islamists. Elalamy's novel Paris, mon bled (the term bled is Franco-Arab slang that equates to the cockney "manor" or "turf") tells the story of Abdelkhader, a young Moroccan living on one of the wretched council estates on the outskirts of Paris, who moves between several cultures - French, Moroccan, Anglo-American pop culture - all at once. It crackles with multicultural, multilingual wit. Yet the book was rejected by a Parisian publisher on the grounds that it wasn't "Moroccan" enough. "I didn't understand what he meant," he says. "I am Moroccan, I was born here, I live here, and this book is how many Moroccans see the world, not in terms of folklore, which is for tourists or anthropologists anyway, but as a real experience of the complexity of modern life."
Elalamy takes as his peers not the distinguished francophone, and mainly Paris-based, generation of Moroccan writers such as Tahar Ben Jelloun or Driss ChraIbi, but rather the young rappers of Casablanca, Meknes and Fez who, he says, offer the first line of cultural resistance. These young rappers, with names such as Thug Killah and DJ SaId, appear at underground and often illegal venues, performing in French, English and Moroccan Arabic. They deal with the predictable themes of social exclusion, smoking kif and avoiding the police; however, they do offer a genuinely new voice in Moroccan culture - new because it is authentically modern. "That's the whole point," says Elalamy, who is currently having Paris, mon bled set to music by the London-based group MoMo (Music of Moroccan Origin). "The trick is to write about what really happens here."
But there is one subject off-limits for the new-wave Moroccan rappers: the rise of Islamic militancy. This is not because they support it (they obviously don't) but because the dangers of offending a local imam are self-evident. The risks are even greater for female writers and intellectuals who dare to speak out - women such as Fatima Mernissi, probably the foremost feminist thinker in the Arab world, who lives in Rabat.
Yet the book that has been stealing all the headlines recently is Nadia Yassine's Toutes voiles dehors (All Veils Outside), which argues - bizarrely quoting such avatars of modernity as Roland Barthes - that "taking the veil" is "an act of liberation". Nadia, who is the daughter of Sheikh Yassine and is herself a prominent figure in al-'Adl wal-Ihsan, wrote the book in French to export the revolution. Tragically, she is in tune with the times: the rise of Islamic fundamentalism in Morocco has been a phenomenon in large part driven by poor or working-class women who find in the mosque the social support - literacy classes, financial aid - that the government cannot or will not give them.
Middle-class Moroccans, not without some complacency, perhaps, argue that their culture is rich, diverse and old enough to withstand the invasion of what they see as an alien culture exported from Saudi Arabia. They also observe that their young king, Mohammed VI, as a direct descendant of the Prophet, has not only a political but a spiritual legitimacy that nullifies much of the manoeuvring from the Islamists.
But this is still a dangerously divided country. Shortly after the last elections, which took place in September, the king threw a party in Marrakesh in honour of his friend the US rapper Puff Daddy (or P Diddy). The guests included Naomi Campbell, Elton John and other luminaries who were both unknown and unintelligible to the average Moroccan. Indeed, to the illiterate peasant or wretched urban shanty-town dweller, they might as well have arrived from another planet. This simple image explains, if it does not justify, why political Islam, which refuses to see the world on anything but its own terms, has taken such a firm grip here. What no one can really guess today in Morocco is how long those two worlds will continue to coexist.
Andrew Hussey is the author of The Game of War: the life and death of Guy Debord