In recent years, westerners and increasingly Muslim youth have fallen for the idea that Arab and Middle Eastern cultures have always been dominated by religion, and that the ideas and attitudes associated with secular cosmopolitanism are completely alien, a corrosive import from the west. This is a dangerous misinterpretation which threatens to erase a rich tradition within Middle Eastern cultures. Nationalists, fundamentalists and 'warriors of terror' should not be allowed to steal the past, to put it to the service of their own present and desired future. We should remind ourselves of recent - 19th and 20th century - history, a history of lively and varied social and cultural formations in which religion was only one element, and one that, for most of the 20th century, was not dominant.

I use the word cosmopolitan to describe these relatively open, diverse and tolerant urban cultures. It is not a precise concept, and it has been embroiled in many an ideological contest, but it captures the acceptance of difference, social vitality and a modern open disposition, which is urgently needed as an antidote to millennialism and the simple-mindedness of crusaders and jihadists.

Cosmopolitanism is the product of empires. These brought diverse peoples together into urban centres, where they engage in a wide variety of relationships, economic, political and personal. The two pertinent empires for the history of the Middle East since the 19th century are the Ottoman and the British, with the additional strong influences of French language and culture and German nationalism.

The Ottoman Empire (1281–1923) is sometimes described as 'cosmopolitan', in that it held together a remarkably broad mix of people, ethnic groups and religions, in a relatively peaceful and stable co-existence. Its 'millet system' is often touted as a model of tolerance and harmony. However, the non-Muslim (and non-Sunni) millets were always legally inferior and loaded with restrictions on residence, dress and comportment, and worship. They were subject to extortion by rapacious governors and mamlukes, who frequently passed laws which impacted unfairly on non-Muslims in order to raise tax-revenue.

The mere co-presence of diverse peoples does not entail social and cultural mixing. For the most part individuals were confined within social and topographical boundaries, under the authority of their religious chiefs, in turn subservient to the power of the Sultan.

This is not 'cosmopolitanism'. For that we need to look at certain key cities in the 19th and early 20th century, which emerged as the Ottoman Empire began to decline. It is then, under the twin processes of modernity and capitalism, supported by the increasing hegemony of the European powers in the area, especially Britain, that these communal barriers become more permeable.

During this time economic and cultural modernity began to flourish in the urban centres of Istanbul, Cairo, Alexandria and Beirut. New intellectuals and statesmen, while ideologically attached to Islamic and Ottoman roots, adopted new lifestyles and associations, and explored new horizons, stimulated, in part, by the painful realisation of European superiority in wealth and arms.

One enclave of cultural as well as political activism was that of the Young Ottomans, a group of intellectuals versed in European languages and ideas, but seeking a renaissance of Islamic/Ottoman civilization. A prominent member was Namik Kemal, a poet, essayist and political philosopher, deeply influenced by European thought: he translated Montesqieu, debated Voltaire and Condorcet, and followed the nationalist models of Garibaldi and Mazzini. Kemal, and many other Young Ottomans, spent periods of exile in Paris, London and Geneva, where they published journals that were prohibited in Istanbul, intriguing with patrons and factions in and out of government. Intellectually and politically, they were cosmopolitans.

Yet Kemal was firmly attached to the idea that a revived Islam must form the basis of society and government. He tried to find Islamic idioms for expressing the main ideas and concepts of the Enlightenment. He was highly critical of the ruling functionaries of the Porte (empire) for their blind imitation of Europe, but at the same time he was a noted drinker. For these intellectuals and reformers Islam becomes an ideology of national authenticity rather than strict observance.

Many of the members of the Ottoman elites, politicians and high functionaries, and even some Young Ottomans, became members of Freemason lodges. A similar situation prevailed in Egypt in the 19th and 20th centuries. The most renowned Muslim reformer of the time, Jamaleddin al-Afghani (1838–1897) known as Asadabadi to Iranians, was a member (by some reports a Master) of such a lodge in Egypt.

The cosmopolitanism of al-Afghani spanned not only the European-Muslim boundaries, but also inter-Muslim cultures. He operated between British India, Iran, Egypt and Turkey, as well as the European capitals. He worked in Persian, Turkish and Arabic, and knew some French. He debated with Indian Muslim reformers and Arab clerics, and his best-known work was a polemic with the anti-religious French thinker Ernst Renan. In this latter work Afghani advances a rationalist explanation of the formation and history of religion and of its social functions, arguments which led to accusations of atheism by opponents in the Muslim world.

Although al-Afghani's pan-Islamism was, like the Young Ottomans, aimed at the restoration of Islam to its pristine origins, he used cosmopolitan intellectual modes, and lived a cosmopolitan social life. He was known to frequent cafes and clubs, to be fond of cognac, and was rumoured to have illicit sexual encounters. Recent Arab historians who wrote on these aspects of his life have been attacked by orthodox Muslims who claim him as an intellectual ancestor, and would rather not face up to the ambiguity of his life.

Masonic lodges, cafes and salons were the main venues of cosmopolitan culture, but in 19th century Istanbul taverns also featured. The prohibition of alcohol is iconic for orthodox and political Islam, as a marker of authenticity and distinction from the dissolute west. But this, of course, only contributed to the romance of drink throughout Middle Eastern societies. Drinking, its mystery, intrigue and romance are celebrated in poetry, sufism (mysticism) and belles lettres. Istanbul was dotted with drinking cultures, high and low, from the sumptuous wine tables of the rich to the taverns of the soldiery and awbash, the rabble. Historically, the respectable drank in private, but in Istanbul, male drinking cultures became respectable, and open: a sign of modernity.

According to Francois Georgeon's account, Sultan Mahmud II (r. 1808–39) was the first reforming ruler to relax rules governing drinking. He modeled himself on European rulers, and included alcohol as a feature of public dinners and receptions. Champagne, which was not entirely new to the Ottoman court, came out in public. Over the course of the century, and among the modern elites and the official classes, drink came to be associated with being modern and with 'civilisation', madaniyat. Later in the century the emerging bureaucratic class became the vanguard of the drinking classes. To cater for them a new type of refined and opulent tavern, the meyhane, came into existence, with a professional guild of tavern keepers trained in the arts of serving drink and its accompaniments of mezze, and in the skills of nursing a nargila (water-pipe). Among the consumers, a new adab, etiquette and lore of drink determined a new kind of savoir boire.

Much of this new culture of drinking revolved around raki/arak, a distilled spirit flavoured with mastic or anise. It became an identity marker as a specifically native drink in contrast with European wine. It acquired the honorific description of arslan sutu (lion's milk), and in Arabic (at least in Iraq) as halib sba', (in reference to its milky colour when water is added) becoming the drink of choice in the cafes, clubs and salons of intellectuals and reformers, which included Kemal, and the statesman Midhat Pasha. Later in the century, under the more religious and authoritarian reign of Abdul-Hamid II (r. 1875–1908) there was a backlash against this drinking culture, both religious and medical, but apparently with little effect.

Raki was to feature again as part of the culture of the Turkish Republic under Ataturk, himself a noted devotee of the beverage, and it retains a powerful symbolic role. In 1994, in the aftermath of municipal elections that brought the Islamic Refah Partisi to power in Istanbul, one of the first issues that arose between the Islamic mayors and the Kemalist bourgeoisie was that of drinking.

The bars and restaurants of Beyoglu, the cosmopolitan centre of the city, were targeted by the mayor, who did not dare to ban alcohol, but did introduce rules restricting the visibility of drink. Establishments were requested not to allow drinking on terraces and street tables, and to hide their drinkers behind curtains. An outcry by the modern bourgeoisie, with demonstrations of street drinking, soon obliged the Mayor to back down. On a recent visit to Istanbul I came across two new bars in Beyoglu: one named Victor Cohen Seraphanesi (wine bar), the other with a typical Greek name, Stavros Seraphanesi. On inquiry, it seemed that both were run by Turkish Muslim entrepreneurs who acquired the old names in order to recreate the atmosphere and associations of the old 'cosmopolitan' Beyoglu.

But Istanbul was not the only site of Islamic cosmopolitanism. Egypt in the first half of the 20th century hosted an unprecedented flourishing of intellectual and artistic movements, whose centre was Cairo. The new Egyptian university, a lively press, a film industry, an artistic and musical renaissance and intellectual openness, all looked to the wider world for inspiration and innovation.

The work of Egyptian polymath Taha Hussein exemplified a period characterized by the exciting possibilities of cross-pollinating Arab and European thought and culture. The 1932 Congress of Arab Music in Cairo was attended both by musicians and theorists from the Arab world and major European figures such as the composers Bela Bartok and Paul Hindemith. Its agenda was explicitly about debating the links between tradition and modernity, particularism and universality. (Paradoxically it was Bartok who defended traditional music against the Arab modernists who proclaimed the decadence of the old, and the necessity to innovate and evolve in line with universal 'progress'.)

The British anthropologist E Evans Pritchard, who took up the chair of philosophy and sociology at the Egyptian University, gave his seminal lectures on primitive religion to large audiences. Tawfiq al-Hakim's novel of 1938 A Bird from the East also dramatised the relationship between Arab and French culture.

The films of the period - from a generation of innovative directors like Kamal Selim, Salah Abu Seif and Youssef Shahin - portray a universe of romance and music in social settings contrasting the old and the new, the popular quarters and the Europeanised suburbs. The Cairene cultural mix was cosmopolitan in a much more profound sense than the celebrated European-Levantine myth of Alexandria (famously romanticised in Laurence Durrell's Alexandria Quartet).

This heady moment came to an end with the coup of 1952, and the ascension of Gamal Abdel-Nasser to the presidency in 1954. Following the tri-partite invasion of 1956, which ended in humiliation for the British and French, Egypt became a bastion of Arab nationalism, modeled on Soviet-style command economy. The expulsion of the diverse Levantine and European communities that followed undermined that cosmopolitanism. But once again this is not a simple story of European-flavoured cosmopolitanism pitted against authentic Arab or Islamic identity. Arab nationalism was deeply influenced by German Romantic nationalism (as well as Soviet socialism), which itself was explicitly anti-cosmopolitan. This view came down heavily on the side of culture as opposed to (implicitly decadent, cosmopolitan) 'civilisation', a culture supposedly rooted in blood and soil. Civilisation was a superficial veneer, artificial, seductive to the weak and fashionable, which undermined the natural rootedness of volk culture.

Nationalism aspires to purity, rootedness, inevitability, whereas the cosmopolitan is hybrid, shifting and uncontainable. Cosmopolitanism is a threat and a challenge to nationalism, just as it is to religious fundamentalism.

In the first half of the 20th century a generation of outward-looking intellectual Muslim reformers was replaced by a generation of populist leaders interested in mass mobilisation, with a much more puritanical and nativist notion of Islam, inspired most notably by Hassan al-Banna's Muslim Brotherhood.

These are the 'fundamentalists'. Their ideology was one of a return to the purity of early Islam and the first generations, hence 'Salafi' (salaf means 'ancestors), but their politics was essentially based on modern, populist mass movement. Their appeal, in large part, was of national liberation from foreign rule.

On the symbolic level this meant purging 'foreign' practices and lifestyles, and rejecting not only the Europeans but also their compatriots and co-religionists who adopted European ways. They rejected precisely the forms and styles considered 'cosmopolitan'. In this respect nationalists and Salafists - by no means natural partners - found common cause against cosmopolitanism. An essential aspect of both programmes is the perceived negative influence of western culture: al-ghazw al-fikri; alien ideas and corrupt life styles.

Much has been made of the fact that Islamic fundamentalism is a global phenomenon, looking outward to recruit not only in Muslim countries but across the west. There has been an internationalisation of Islamism through the Afghan wars, then through the spread of migrant and trans-national communities and networks. But this trans-nationalism is totally distinct from the thrust and connotation of 'cosmopolitanism'. While the networks of communication and travel are transnational, the ideologies and perspective of global Islam are directed at social particularism and narrow exclusiveness.

While global Islam is in actuality diverse, multi-layered and in many locations successfully hybridised with local cultures, the flavour of Salafism insists on a narrow, anachronistic and putatively 'pure' notion of Islam which, as we have seen, bears little relation to the actual lived history of any Middle Eastern country, and expunges from collective memory the traces of lived cosmopolitanism. Buried under the Goliath forces of globalisation, rising nationalism and fundamentalism, the unique contribution of Middle Eastern cosmopolitan culture needs to be respected and revived.

This essay is based on Sami Zubaida's inaugural lecture as Professor at Birkbeck College, London