NEW DELHI — India’s Supreme Court ruled that a Hindu temple could be built on the site of a razed mosque, a historic verdict that came after decades of legal wrangling, violence and tensions between Hindus and Muslims.

The disputed land in the town of Ayodhya in northern India must pass to a trust within three months, the judges said, upholding the claim of one of the Hindu litigants in the case. A Muslim group will receive land at an alternate location for a potential mosque.

The verdict in the decades-old dispute is a major victory for Prime Minister Narendra Modi, who won reelection in a landslide in May. The building of a temple to the Hindu god Ram is a long-held objective of India’s ruling Bharatiya Janata Party.

Many Hindus worship the site as the spot where Ram was born and believe that a Hindu temple once stood there. In the 16th century, the Babri mosque was built at the same location. In 1992, Hindu extremists illegally destroyed the mosque, an act that set off deadly communal riots across the country.

Ahead of Saturday’s verdict, authorities beefed up security precautions across the country. In India’s largest state, Uttar Pradesh, schools were shut in anticipation of possible unrest. Restrictions on public gatherings were implemented in Delhi and Mumbai, India’s two largest cities, according to local news reports.

Prime Minister Narendra Modi called for calm after the verdict. “My appeal to my fellow citizens is to maintain peace, harmony and unity,” he wrote on Twitter on Saturday. “This decision will further strengthen the common man’s confidence in the judicial process.”

The land at the heart of the disputed site in Ayodhya is just 2.77 acres in size and has been the subject of a legal battle going back to the 1950s.

In 2010, an appeals court in Uttar Pradesh issued a verdict splitting the land three ways between two Hindu groups and one Muslim group — a ruling rejected by all parties.

Attempts to mediate the dispute failed and in August, the Supreme Court began 40 days of hearings to reach a judgment.

Outside the Supreme Court on Saturday, shouts of “Jai Shri Ram!” — victory to Lord Ram — and “We will build a temple there!” broke out after the verdict was announced. Some blew conch shells, a traditional Hindu signal of triumph.

Tania Dutta contributed reporting.