NEW DELHI — India’s Supreme Court ruled in favor of Hindus on Saturday in a decades-old dispute over a holy site contested by Muslims, handing the prime minister and his followers a major victory in their quest to remake the country as Hindu and shift it further from its secular foundation.

The ruling greenlighted construction of a Hindu temple on a site where a mosque had stood before Hindu devotees destroyed it in 1992 with sledgehammers and their bare hands. The demolition of the Babri Mosque in the city of Ayodhya set the tone for sectarian tensions that haunt India today.

The prime minister, Narendra Modi, and his Bharatiya Janata Party swept India’s elections in May by campaigning on a Hindu nationalist agenda, and the court case became an emotionally charged flash point. The party cast its quest to build a temple as a key step in establishing India as Hindu, wiping away centuries of oppression at the hands of the Muslim Mughal Empire and British colonialists.

Many Hindus believe that the disputed site was the birthplace of their revered god Ram and that an earlier temple was demolished during Mughal rule to build the mosque. The case has been in Indian courts since the 1950s, but when it reached the Supreme Court in 2010, the deity Ram was given legal standing, awkwardly pitting the god Hindus revere most against the country’s Muslim population.

Many of India’s Muslims fear that the court’s decision will relegate them to second-class citizenship and empower Hindu extremists. Though many appeared to accept the ruling with sullen resignation, they see an India where mob lynchings of Muslims are seldom condemned by the government and where members of the governing party are implicated in sectarian violence.

Mr. Modi tried to calm those fears in an address to the nation on Saturday night.

“Today’s message is to unite, to associate and to live together,” Mr. Modi said. “In the new India, fear, animosity and negativity should have no place.”

In its highly anticipated ruling, the five-judge panel unanimously decided that the sliver of barren land in question — barely three acres — would be placed in a government-run trust. The decision allows Hindus to construct a temple, which they have planned since the Babri Mosque was destroyed.

The court also ruled that Muslims would be given five acres to build a mosque at a prominent site in Ayodhya, the town at the center of the dispute, in the northern state of Uttar Pradesh.

When the Babri Mosque was demolished by Hindu extremists, it set off riots across the country that killed around 2,000 people in some of the worst violence India had seen since its bloody partition in 1947. In place of the mosque, Hindus erected a tent resembling a temple, which still stands and draws thousands of tourists every day.

An Indian security officer guarding the Babri Mosque in Ayodhya in 1990. The site was claimed by both Muslims and Hindus, but India’s top court favored Hindus in a ruling on Saturday.Credit…Barbara Walton/Associated Press

The mosque was built in the 1500s during Mughal rule, a period that many right-wing Hindus believe serves as a reminder of their humiliation under Muslim occupation. Although sites like the Taj Mahal — also built under the Mughals — are considered famous symbols of India, right-wing Hindus see them as testaments to past oppression.

Some Hindu nationalists want to erase that history and replace it with symbols that reinforce India as a Hindu nation. About 80 percent of India’s population is Hindu.

“Post the independence of our country, we have erased all the symbols of British imperialism,” said Ram Madhav, general secretary of the Bharatiya Janata Party, or B.J.P. “The names of our roads have been changed, the statues of Queen Elizabeth and all of them have been removed.”

India should undergo a similar exorcism of certain symbols of Mughal rule, including the Babri Mosque, Mr. Madhav said, calling the 300-year reign of the Mughal Muslim emperors “cruel.”

“It’s as simple as that,” he said. “This is not about religion. We are not against any religion. India is one of the most religiously diverse places in the world.”

When the Supreme Court announced its decision, lawyers outside the court yelled, “Hail Lord Ram” while Hindu devotees blew conch shell horns, a celebratory tradition.

In Ayodhya, just yards from the disputed site, Indian sadhus shouted, “Praise mother India,” while devotees passed out sweets to mark the victory. But not all pockets of Ayodhya were filled with jubilation.

Much of the town’s Muslims kept off the streets and tried to keep their heads down. Some appeared to hope that now that the decades-long court decision had been settled, the sectarian tensions that have become a way of life in Ayodhya would finally ease.

Iqbal Ansari, a resident of Ayodhya whose father was a litigant in the case and had demanded the Babri Mosque be restored, said he welcomed the decision and hoped it would end years of sectarian strife.

“We should stop seeing each other from the religious prism,” he said. “The court’s verdict is final, and we will not appeal against it.”

Mr. Modi’s government praised the ruling but was quick to call for unity and warned Hindus against boisterous celebrations for fear they would set off clashes. While India under Mr. Modi has adopted a Hindu tilt, the prime minister has also focused on raising India’s profile on the international stage.

Hindu fundamentalists attacking a wall of the Babri Mosque in 1992.Credit…Douglas E. Curran/Agence France-Presse — Getty Images

Officials in Delhi have been dismayed by the persistent news coverage of India’s sectarian disharmony, including antigovernment protests in the Muslim-majority state of Jammu and Kashmir, which was stripped of its autonomy in August.

In the hours after Saturday’s ruling, India’s Muslims were divided between those who want to contest the decision and those who want to move on for the sake of sectarian harmony. Those who want to contest it have come to see the restoration of the Babri Mosque as a proclamation of Muslims’ place in India, and they fear that more religious sites will be targeted for destruction.

After the court announced its verdict, senior government officials were quick to call journalists in and promise — anonymously — that no more mosques would be destroyed and that they, too, wanted to move on and focus on building the nation. Before this year’s election, Mr. Modi promised to deliver ambitious growth, to make India a $5 trillion economy by 2025. But growth so far has been sluggish, with unemployment reaching a 45-year high.

“There is short-term fear about communal tensions,” said Milan Vaishnav, the director of the Carnegie Endowment for International Peace’s South Asia program. “The soil is pretty fertile for conflict.”

“The longer term fear,” he added, “is do Muslims and other minorities of India begin to feel resigned to a permanent status as second-class citizens? The genius of India in the way it was constructed is that it avoided that tension eating away at the state, unlike its neighbors.”

The ruling comes just three months after Mr. Modi’s government achieved another goal written into his party’s manifesto by stripping the Muslim-majority state of Kashmir of its autonomy, increasing central government control over the territory, which Pakistan also claims.

Many in the B.J.P. say they believe that Muslims and other minorities in India, including Christians, have been given a special status that has set them apart from their Hindu peers, creating a nation with a tiered structure that they would like to flatten. Hindu temples, for example, are controlled by the government, while Christians and Muslims control their own churches and mosques.

Ahead of the verdict, schools were shut and 4,000 security officers were deployed to the area in case of sectarian violence. Rallies were banned, shops barred from selling kerosene and people prevented from collecting bricks or stones.

Vendors selling garlands in May to pilgrims approaching the site of the proposed Hindu temple. Many Hindus believe that the disputed site was the birthplace of their revered god Ram.Credit…Rebecca Conway for The New York Times

A rush of Hindu pilgrims had visited Ayodhya ahead of the verdict. Sudarshan Jain and his family, pilgrims from Rajasthan, a state hundreds of miles away, visited an open-air workshop where craftsmen chiseled floral designs and figurines of Ram on pink sandstone slabs that will form the temple. Its first floor is ready to be fixed in place, the craftsmen said.

Hindus from around the world have donated hundreds of bricks carved with the inscription “Sri Ram,” hoping that the court would rule in favor of building the temple. The bricks have sat in organized piles next to the contested site, numbered and ready to be fixed and shaped into a temple, which devotees say can be constructed within hours once they get the green light.

“These are not stones, but feelings of millions of Hindus,” Mr. Jain said. “Now the dream is going to be a reality.”

Sitting in the courtyard of his home in Ayodhya, Haji Mahboob Ahmad, a litigant who had wanted the mosque to be rebuilt, said that Muslims would accept a ruling against them but that he feared that right-wing Hindu forces would be emboldened and more mosques would be destroyed.

“Violence against Muslims will rise, and it will become institutionalized,” said Mr. Ahmad, 75, who had to flee the town for a month after the mosque was demolished nearly 30 years ago.

This article first appeared on NYTimes