The unexpected decision to divide the property initially suggested a political solution as much as a legal one. But Harish Salve, a former solicitor general of India, said the court had apparently based its decision on historical accounts suggesting that for centuries Hindus and Muslims had worshiped together at the site before they were segregated during British rule in the 1850s.

Image An Indian Muslim walked past security personnel in Ayodhya, India, on Thursday Credit... Rajesh Kumar Singh/Associated Press

With this legacy, the court concluded that the entire property should be considered jointly held by Muslims and Hindus and distributed under relevant Indian property statutes, Mr. Salve said, which divide contested properties on the principle of fairness.

“It looks pretty good,” Mr. Salve said, rating the decision as “9 points out of 10.”

Under the court’s ruling, two-thirds of the land will go to Hindu groups while the remaining third will be awarded to Muslims. Lawyers for Hindus and for Muslims expressed dissatisfaction and promised to appeal the ruling to the Supreme Court.

“There is no reason of any loss of hope,” said Zafaryab Jilana, a lawyer representing one of the Muslim parties to the case, speaking on national television. “We do not agree with the formula of giving one-third of the land to Muslims.”

The case required the judicial panel to wade deeply into India’s contested religious history. Lawyers for Hindu groups had argued that the Ayodhya site was the birthplace of one of Hinduism’s most revered deities, Ram. They contended that a temple to Ram had existed on the site until it was demolished to make way for the Babri Masjid, constructed in the 16th century by India’s first Mughal ruler.

Soon after the judges read the decision in a closed hearing, lawyers rushed to hundreds of reporters waiting outside the courthouse in Lucknow, the capital of Uttar Pradesh. “The judgment is in favor of Hindus,” said H. S. Jain, a lawyer for one of the Hindu groups in the case. “The belief of Hindus that this is the birthplace of Ram is upheld.”