The apex court said the faith of Hindus that Lord Ram was born at the site was undisputed, and he is symbolically the owner of the land.
Settling a fractious issue that goes back more than a century, the Supreme Court in a historic verdict on Saturday backed the construction of a Ram temple by a government trust at the disputed site in Ayodhya, and ruled that an alternative five-acre plot must be found for a mosque in the Hindu holy town.
Delivering a unanimous verdict on a case that has long polarised the country and frayed the secular tapestry of Indian society, a five-judge bench of the apex court headed by Chief Justice of India Ranjan Gogoi said the faith of Hindus that Lord Ram was born at the site was undisputed, and he is symbolically the owner of the land.
Justice Gogoi is due to retire on November 17.
Yet, it is also clear that the destruction of the 16th century three-domed structure by Hindu kar sevaks, who want to build a Ram temple there, was a wrong that 'must be remedied', the ruling said.
The judgment said it is not concerned with faith and belief, and instead treated the case as a title dispute over land between three parties -- the Sunni Muslim Waqf Board, the Nirmohi Akhara, a Hindu group, and the symbolic Lord Rama designated as Ram Lalla Virajman.
The judgment running into 1,045 pages was widely welcomed by Hindu politicians and groups, while the Muslim leadership said they will accept the verdict, even though they described it as flawed.
Still, they called for peace and calm, and leaders across the political spectrum noted that it was now time to move on.
'Whether it is devotion to Ram or Rahim, now is time for everybody to strengthen devotion to India,' Prime Minister Narendra Modi said in a tweet.
Later, in an address to the nation, Modi said peace, unity and amity are essential for development of India and described November 9 as a day to forget any bitterness one may have. He said there is no place for fear, bitterness and negativity in new India.
The dispute over the site of Babri Masjid, a three-domed mosque built by or at the behest of Mughal emperor Babur, dates back centuries with Hindus contending that the invading Muslim armies had razed an existing Ram temple to erect the mosque.
However, it turned into a legal dispute in 1885 when a mahant went to court seeking permission to build a canopy outside the mosque.
The plea was dismissed.
In December 1949, unidentified miscreants spirited an idol of Lord Ram into the mosque. The structure was destroyed by a large mob of kar sevaks on December 6, 1992.
The demolition triggered nationwide Hindu-Muslim riots, more so in north India and Mumbai, which left many hundreds dead.
Subsequently, Muslim extremists angered by the demolition and the riots, carried out a series of bombings in Mumbai on March 12, 1993, which left hundreds dead.
'The dispute is over immovable property. The court does not decide title on the basis of faith or belief but on the basis of evidence,' the judgment said, delivered at the end of a marathon 40-day hearing-- the second longest in the history of apex court.
'The fact that there lay a temple beneath the destroyed structure has been established by the Archaeological Survey of India (ASI) and the underlying structure was not an Islamic structure.'
'On the balance of probabilities, there is clear evidence to indicate that the worship by the Hindus in the outer courtyard' has continued unimpeded even before 1857 when the British annexed Oudh region.
'The Muslims have offered no evidence to indicate that they were in exclusive possession' of the mosque before 1857, it said.
'The faith of the Hindus that Lord Ram was born at the demolished structure is undisputed.'
The court also went on to say that the Constitution must ensure that a wrong committed must be remedied.
'Justice would not prevail if the Court were to overlook the entitlement of the Muslims who have been deprived of the structure of the mosque through means which should not have been employed in a secular nation committed to the rule of law.'
To remedy that wrong, the court asked the Centre to allot a five-acre plot in a 'prominent' location in Ayodhya in Uttar Pradesh for constructing a new mosque.
The disputed 2.77-acre plot will for now remain with a central government receiver, who will hand it over to a government-created trust that must be set up within three months. The trust will be tasked with the construction of the temple.
The verdict in the politically-sensitive Ram Janmbhoomi-Babri Masjid land dispute case was one of the most important and most anticipated judgments in India's history the apex court bench that also comprised Justices S A Bobde, D Y Chandrachud, Ashok Bhushan and S Abdul Nazeer said possession of the disputed 2.77 acre land rights will be handed over to the deity Ram Lalla.
As security was tightened at communally sensitive places across the country, Mohan Bhagwat, the chief of ruling Bharatiya Janata Party's parent organisation the Rashtriya Swayamsevak Sangh, said the verdict should not be seen as anybody's victory or defeat.
The building of a Ram temple is a long-held objective of the BJP.
There were no reports of violence or unrest from Ayodhya, where a massive police force was deployed, or any other part of the country.
The verdict was pronounced on 14 appeals filed in the apex court against the 2010 Allahabad high court judgment, delivered in four civil suits, that the 2.77-acre land in Ayodhya be partitioned equally among the three parties -- the Sunni Waqf Board, the Nirmohi Akhara and 'Ram Lalla'.
The bench said the high court wrongly decided the title suit by resorting to partitioning of the disputed land in three parts.
'The disputed site was government land in the revenue records,' the court said.
As Justice Gogoi read out the operative part of the verdict for 45 minutes, people belonging to both Hindu and Muslim communities in Ayodhya sat glued before Television sets, while the tech-savvy youth kept a tab on their mobiles phones.
Relief appeared to be the overwhelming emotion in Ayodhya as its residents said the verdict has heralded a new dawn and brought closure to a lingering dispute.
"The judgment has ended the uncertainty on how the dispute would be settled," said Anand Kumar, a resident.
At some places, people chanted 'Jai Shri Ram' and burst crackers.
Mohammed Sajid, who runs a tailoring shop, said he felt the verdict is 'incomplete' but did not elaborate.
C S Vaidyanathan, lawyer for deity 'Ram Lalla', said the verdict is very balanced and it is a victory of people.
The Uttar Pradesh Sunni Central Waqf Board, one of the main litigants, welcomed the Supreme Court verdict and said it has no plans to challenge it.
In his initial reaction soon after the judgement, Board's counsel Zafaryab Jilani had said in Delhi, "The Ayodhya verdict has a lot of contradictions. We will seek a review as we are not satisfied with the verdict."
Talking to PTI on phone later, Jilani, however, clarified he had reacted as secretary of the All India Muslim Personal Law Board (AIMPLB) and and not as the counsel for the Sunni Waqf Board.
The Nirmohi Akhara said it has no 'regrets' regarding the verdict.
Union Home Minister Amit Shah appealed to all communities to accept the verdict and maintain peace and remain committed for 'Ek Bharat Shreshtha Bharat' while Defence Minister Rajnath Singh urged everyone to take the verdict with equanimity and magnanimity.
The Congress said it respects the verdict and is in favour of construction of Ram temple.
Prominent Muslim leaders appealed for peace and harmony even as they expressed surprise.
"I was surprised to see the ruling and it's beyond my understanding. I feel there were enough evidences in favour of the mosque but these were not taken into consideration," Mufti Abul Qasim Nomani, the current Mohtamim (Vice-Chancellor) of the Islamic seminary Darul Uloom Deoband, said.
Read the 1045-page verdict here.