The observations came after BJP leader Subramanian Swamy mentioned the matter seeking urgent hearing of the issue.
Chief Justice JS Khehar said that if negotiations break down, the apex court would appoint a mediator.
Swamy said it is hard to make both communities sit together, thus necessitating the judiciary to intervene.
The Supreme Court on Tuesday observed that the Ayodhya dispute must be settled amicably and all parties must hold discussion out of court to find an amicable solution to the issue which is both sensitive and sentimental issue.
He had also said that the hurdles on the path of construction of a grand Ram temple will be gradually removed and its work will soon start in Ayodhya. And the Muslims see it as the Babri Masjid.
Meanwhile, Subramanian Swamy, one of the petitioners, suggested the temple should be built at the disputed land and that the mosque be built across the Saryu river.
While adjourning the hearing, the Supreme Court directed Swamy to inform the court about the final decision after holding talks with both the parties in the case.
In what comes as really surprising, Supreme Court of India a little while advised an out-of-court settlement for the decades-old Ayodhya Rama Mandir issue. If required, you must choose a moderator to end the dispute.
"You must make fresh attempts to arrive at a consensual decision. In the past, we had sat for negotiations but due to undue interference by political parties no solution could be found, hence the Supreme Court should give a final verdict", he added.
CJI Khehar even went on to say he was ready to mediate on the controversial issue if the parties concerned want him to.
In his petition, Swamy had claimed that under the practices prevalent in Islamic countries, a mosque could be shifted to any other place for public purposes like constructing a road, whereas a temple once constructed cannot be touched.