NEW DELHI, OCT. 30 -- Police fired on thousands of Hindu militants and holy men who tried to storm barricades and begin construction of a temple on the site of an existing mosque today in the northern town of Ayodhya.

Five people died in the incident, and at least 15 others were killed in religious violence elsewhere in India.

Witnesses and government officials said that despite heavy security around Ayodhya, site of the disputed Babri Masjid mosque, thousands of Hindu militants, including a group of naked holy men smeared with ashes, gathered for an early morning charge at the Islamic shrine.

Police initially tried to fight off the mob with batons and tear gas but eventually opened fire at three places, the witnesses and officials said.

Thousands of young men broke through police cordons, entered the small mosque, pried bricks from the wall and chipped bits of plaster from its three domes, according to news reports. They planted an orange flag -- the Hindu color -- on each dome before police chased them away.

Hindu militants' attempts to replace the 16th-century mosque with a Hindu temple stem from their belief that it stands on the birthplace of Ram, a Hindu god.

Independent scholars say there is virtually no evidence for this claim, but the dispute has become infused with religious hatreds in India that remain unabated four centuries after Moslem emperors invaded the Hindu-dominated subcontinent.

The dispute over the mosque has touched off sporadic riots in India for more than a year, claiming hundreds of lives. Tensions generated by the issue have also fed a political crisis that has brought Prime Minister V.P. Singh's minority government to the brink of collapse.

Singh lost his parliamentary majority a week ago when the Hindu revivalist Bharatiya Janata Party (BJP) withdrew its support following the arrest of its leader, L.K. Advani, who had organized a march to Ayodhya. The prime minister appears likely to lose a confidence vote scheduled for Nov. 7, a defeat that analysts here say will probably lead to new elections.

Responding to dissidents within his own Janata Party who want to avoid elections by replacing Singh with a new leader from within the party, the prime minister today offered to resign "if the members of Parliament feel that a change of leadership will serve larger goals."

"The main issue before us is the unity of the country and the upholding of secular credentials and democratic institutions," Singh said in a letter to Janata Party President Sommappa Rayappa Bommai. "It is in the pursuit of these goals that we have sacrificed a whole government."

Janata Party officials said they did not expect the offer to be accepted. But the prime minister's letter echoed several of the themes he has said will guide any new election campaign: opposition to Hindu revivalists, support for an affirmative-action plan to benefit lower social classes, and a claim that Singh, alone among Indian politicians, is willing to take principled stands on major issues.

India's few reliable polling houses have not published any political surveys recently, making it difficult to predict whether such a campaign would find a receptive audience.

Because of his affirmative-action plan, under which 27 percent of government jobs would be set aside for lower and lower-middle castes, the Hindus' traditional social classes, Singh has lost support among India's upper-caste urban intelligentsia. And during his tenure, religious riots, caste riots, border tensions with Pakistan and several violent secessionist movements have affected much of the country, particularly the northern regions where Singh's party is strongest.

Some political pollsters and commentators here have predicted that fears of escalating instability will lead Indian voters back to the Congress Party led by former prime minister Rajiv Gandhi, even though the party is in disarray and Gandhi has so far been unable to mount a political comeback since his ouster 11 months ago.

Besides the violence in Ayodhya, Hindus and Moslems clashed today in several other northern and central cities, causing a total of at least 20 deaths and scores of injuries, according to Indian news reports. Army and paramilitary forces have been called out to enforce curfews in Lucknow, Kanpur, Ahmedabad, Hyderabad and a number of smaller cities.

In an effort to prevent Hindu militants from reaching Ayodhya or igniting violence in nearby cities, Singh's government has canceled trains, sealed roads and arrested an estimated 100,000 people during the past two weeks, including a number of senior BJP leaders.

While BJP activists say they hope to benefit in any new election from religious and nationalist feelings generated by the Ayodhya dispute, senior leaders such as Advani have said repeatedly during the past year that they were not ready for an early vote.

Since the 1989 election that made the BJP the third-largest party in Parliament, Advani has emphasized a careful strategy of supporting secularists such as Singh until the BJP becomes strong enough to win a parliamentary majority. Few New Delhi analysts believe the BJP has reached that point.