Earlier this year, I was in Rishikesh, the first town that the River Ganges meets as it leaves its Himalayan home and embarks upon its long journey through the north Indian plains. The town's place in Indian mythology is not as secure as that of Hardwar, which lies a few miles downstream and which periodically hosts the Kumbh Mela festival of Hinduism; nor is it as famous as Allahabad or Benares, even holier cities further down the Ganges. People seeking greater solitude and wisdom usually head deep into the Himalayas. With its saffron-robed sadhus and ashrams, its yoga and meditation centres, and its internet and dosa cafes, Rishikesh caters to a very modern kind of spiritual tourist: the Beatles came here in the Sixties to learn from Maharishi Mahesh Yogi. Their quick disillusionment seems not to have deterred the stylishly disaffected members of the western middle class who can be found wandering the town's alleys in tie-dye outfits, trying to raise their kundalini in between checking their Hotmail accounts.

I was in Rishikesh to see my aunt, who has just retired to one of the riverside ashrams. She has known a hard life: widowed when she was in her thirties, she worked in small, badly paid teaching jobs to support her three children. In my memory, I can still see her standing at exposed country bus stops in the middle of white-hot summer days. She had come to know comfort, even luxury, of sorts in later life. Her children travel all over the world as members of India's new globalised corporate elite; there are bright grandchildren to engage her at home. But she was happiest in Rishikesh, she told me, living as frugally as she had for much of her life, and devoting her attention to the end of things.

True detachment, however, seemed as difficult to achieve for her as for the spiritual seekers with e-mail. I had only to mention the political situation - India was then threatening to attack Pakistan - for her to say, angrily: "These Muslims need to be taught a lesson. We Hindus have been too soft for too long."

In the past decade, such sentiments have become commonplace among the upper-caste Hindus, both in India and abroad, who form the most loyal constituency of the Hindu-nationalist Bharatiya Janata Party (BJP). They were amplified most recently in Gujarat during the BJP-assisted massacre of more than a thousand Muslims; they go with a middle-class pride in the international prominence of Indian beauty queens, software professionals and Bollywood. Perhaps I wouldn't have found anything odd about my aunt's anti-Muslim passions had I not later gone up to her monastic cell and noticed the large garlanded poster of a well-known Sufi saint of western India.

Did she know that she revered someone born a Muslim? The folk religion to which the Sufi saint belongs, and which millions of Indians still practise, does not acknowledge such modern political categories as Hindu and Muslim. The discrepancy between the narrow nationalist prejudices my aunt had inherited from her class and caste and the affinities she generously formed in her inner world of devotion and prayer is not easily understood; but it is part of the extraordinary makeover undergone by Hinduism since the 19th century, when India first confronted the west and its universalist ideologies of nationalism and progress.

Although it contains the world's third-largest population of Muslims, India, for most people outside it, is a country of "Hindus"; even a "Hindu civilisation", in Samuel Huntington's millenarian world-view. Yet Hinduism was a 19th-century British invention. Even the word Hindu itself is of non-Hindu origin. It was first used by the ancient Persians to refer to the people living near the River Indus (Sindhu in Sanskrit). It then became a convenient shorthand for the rulers of India; it defined those who were not Muslims or Christians.

The persistence of such labels in the west is due not just to ignorance, or to some lingering Christian fear of heathens. Perhaps the urge to fix a single identity for diverse communities comes naturally to people in the highly organised and uniform societies of the west, where cultural diversity now usually means the politically expedient and hardened identities of multiculturalism. Perhaps people who themselves are defined almost exclusively by their citizenship in the nation state and the consumer society cannot but find wholly alien the pre-modern world of multiple identities and faiths in which most Indians still live.

Certainly, most Hindus themselves felt little need for precise self-descriptions, except when faced with questions about religion on official forms. Long after their encounter with the monotheistic religions of Islam and Christianity, they continued to define themselves through their overlapping allegiances to family, caste, linguistic group, region and devotional sect. Religion to them was more unselfconscious practice than rigid belief. Their rituals and deities varied greatly. Both snakes and the ultimate reality of the universe were worshipped in the same region, sometimes by the same person. Religion rarely demanded, as it did with many Muslims or Christians, adherence to a set of theological ideas prescribed by a single prophet, book or authority.

This is why a history of Hinduism, no matter how narrowly conceived, has to describe in effect several very parochial- seeming Indian religions, almost none of which contained the evangelical zeal to save the world. The first of these - the Vedic religion - began with the nomads and pastoralists from central Asia who settled north India in the second millennium BC. It was primarily created by the priestly class of Brahmans, who conducted fire sacrifices with the help of the Vedas, the earliest known Indian scriptures, in order to stave off drought and hunger. But the Brahmans, who also formulated the sacred and social codes of the time, wished to enhance their own glory and power rather than propose a new all-inclusive faith; they presented themselves as the most superior among the four caste groups that emerged during Vedic times and which were based upon racial distinctions between the settlers and the indigenous population of north India, and then upon a division of labour.

A new religion was also far from the minds of the Buddhists, the Jains, and other philosophical and cultural movements that emerged in the sixth and fifth centuries BC to challenge the power of the Brahmans and of the caste hierarchy. People dissatisfied with the sacrificial rituals of the Vedic religion later grew attracted to the egalitarian cults of Shiva and Vishnu that became popular in India around the beginning of the first century AD. However, the Brahmans managed to preserve their status at the top of an ossifying caste system. They zealously guarded their knowledge of Sanskrit and esoteric texts, and their expertise in such matters as the correct pronunciation of mantras. Their specialised knowledge and pan-Indian presence gave them a hold over ruling elites even as the majority of the population followed its own heterodox cults and sects. Their influence can be detected in such Indian texts as the Bhagavad-Gita which, though acknowledging the irrelevance of ritual sacrifices, made a life of virtue inseparable from following the rules of caste.

But India remained too big and diverse to be monopolised by any one book or idea. The Hindu nationalists present the Muslims who ruled India for eight centuries as the flag-bearers of an intolerant monotheism. Yet there was even more religious plurality during that period. Sufism mingled with local faiths; the currently popular devotional cults of Rama and Krishna, and the network of ashrams and sects, expanded fast under the Moghul empire. Medieval India furnishes more evidence of sectarian violence between the worshippers of Shiva and Vishnu than between Hindus and Muslims.

In the 18th century, the British were both appalled and fascinated by the excess of gods, sects and cults they found in India. It was similar to the pagan chaos that a Christian from the eastern provinces of the Roman empire might have encountered in the west just before Constantine's conversion to Christianity. Like the powerful Christians in Rome, the British in India sought and imposed uniformity.

Early 18th-century British scholars of India were familiar at home with the monotheistic and exclusive nature of Christianity. When confronted by diverse Indian religions, therefore, they tended to see similarities, even though these were usually as superficial as those between Judaism, Christianity and Islam. The British assumed that different religious practices could exist only within a single overarching tradition. Equally - because they came from a society that had a relatively high level of literacy - they thought that Indian religion must have canonical texts, just as Christianity did. Their local intermediaries tended to be Brahmans, who alone knew the languages - primarily Sanskrit - needed to study such ancient Indian texts as the Vedas and the Bhagavad-Gita. Together, the British scholars and their Brahman interpreters came up with a canon of sorts, mostly Brahmanical literature and ideology, which they began to identify with a single Hindu religion.

The Brahmanical literature so systematised later created much of the appeal of Indian culture for its foreign connoisseurs, such as the German Romantics, Schopenhauer, Emerson and Thoreau. It also provided the British with the standards by which to judge the state of contemporary religion in India. As few Indians at the time seemed capable of the sublime sentiments found in the Bhagavad-Gita and the Rig-Veda, Hinduism began to seem a degenerate religion, full of such social evils as widow-burning and untouchability, and in desperate need of social engineering: an idea that appealed both to British colonialists and their Brahman collaborators, who had long felt threatened by the non-Brahmanical forms of religion that most Indians followed. It was equally convenient to blame the intrusion of Islam into India for Hinduism's fallen state, even for the caste system, and to describe Hindus as slaves of Muslim tyrants: a terrible fate from which the British had apparently rescued them in order to prepare their path to a high stage of civilisation.

These ideas about the Muslim tyrants, Hindu slaves and British philanthropists were originally set out in such influential books as James Mill's History of British India, which now tell you more about the proselytising vigour of some Enlightened Scots and utilitarians than about Indian history. Nevertheless, they had a profound impact on a new generation of upper-caste Indians who had enjoyed a western-style education. They wished to imitate the success of the British; do for India what a few enterprising men had done for a tiny island; and they found a source of nationalist pride in the newly minted "Hinduism".

Only a tiny minority of upper-caste Indians had known much about the Bhagavad-Gita or the Vedas until the 18th century, when they were translated by British scholars and then presented as sacred texts from the paradisiacal age of this "Hinduism". But in the 19th century, movements dedicated to reforming "Hinduism" and recovering its lost glory grew rapidly, inspired by the ideas of progress and development that British utilitarians and Christian missionaries aggressively promoted in India. Intellectuals in Muslim countries that were exposed to European imperialism also absorbed western influences, but their distrust of the Christian and secular west was deeper. Unlike Muslims, the Hindus tended to borrow more than they rejected. Rammohan Roy (1772-1832), who is often called the "father of modern India", was a Unitarian. He founded the Brahmo Samaj, a reformist society that influenced Rabindranath Tagore and Satyajit Ray, among other leading Indian intellectuals and artists, as part of an attempt to turn Hinduism into a rational, monotheistic religion. The social reformer Dayananda exhorted Indians to return to the Vedas (which contained, according to him, all of modern science), and echoed British missionary denunciations of such "Hindu superstitions" as idol-worship and the caste system. Even the more secular and catholic visions of Gandhi and Nehru - the former a devout Hindu, the latter an agnostic - accepted the premise of a "Hinduism" that had decayed and had to be reformed.

Gandhi drew his political imagery from popular folklore; it made him more effective as a leader of the Indian masses than the upper-caste Hindu politicians who relied upon a textual, or elite Hinduism. But it was Swami Vivekananda (1863-1902) who was mostly responsible for the modernisation of Hinduism. Vivekananda was the middle-class disciple of the illiterate mystic Ramakrishna Paramhansa; but he moved far from his guru's inward-looking spirituality in his attempt to make Hinduism intellectually respectable to both westerners and westernised Indians. In his lectures in England and America, where he acquired a mass following, he presented India as the most ancient and privileged fount of spirituality. At the same time, he exhorted Hindus to embrace western science and materialism in order to shed their backwardness and constitute themselves into a manly nation.

Vivekananda borrowed from both British-constructed Hinduism and European realpolitik, and thus articulated the confused, aggressive desires of a westernised Indian bourgeoisie that was trying to find its identity. But his ambition of regenerating India with the help of western techniques did not sunder him entirely from folk religious traditions. He remained a mystic; and his contradictory rhetoric now seems to prefigure the oddly split personality of the modern Hindu, where devotion to a Muslim saint can coexist with an anti-Muslim nationalism.

The marriage of Indian religiosity and western materialism that Vivekananda tried to arrange makes him the perfect patron saint of the BJP, a party of mostly upper-caste, middle-class Hindus that strives to boost India's nuclear and information technology capabilities and also reveres the cow as holy. A hundred years after Vivekananda's death, the BJP has come closest to realising his project of westernising Hinduism into a nationalist ideology: one that has pretensions to being all-inclusive, yet demonises Muslims and seeks to pre-empt with its rhetoric of egalitarianism the long-overdue political assertion of India's lower-caste groups.

Vivekananda's modern disciples are helped by the rise of the Indian bourgeoisie. Affluent, upper-caste Indians, in India and abroad, largely bankrolled the rise of Hindu nationalists, and long for closer military and economic ties between India and western nations; globalisation helps them work faster towards Vivekananda's desired alliance between an Indian elite and the modern west. As a global class, they are no less ambitious than the one which in the Roman empire embraced Christianity and made it an effective tool of this-worldly power. Hinduism in their hands has never looked more like the Christianity and Islam of popes and mullahs, and less like the multiplicity of unselfconsciously tolerant faiths it still is for most Indians. Their growing prominence suggests that Vivekananda may yet emerge as more influential than Gandhi, Nehru or Tagore - the three great Indian leaders, whose legacy of liberal humanism middle-class India seems to have frittered away. Their quest for western-style machismo, for economic and military muscle, seems to be taking India towards times as intellectually and spiritually oppressive as those the west experienced after its elites chose a severe monotheism as their official ideology.