Those in attendance included cricketing great Sachin Tendulkar, Bollywood star Amitabh Bachchan and multi-billionaire industrialist Mukesh Ambani.
Analysts and critics framed the event as the start of Mr Modi’s election campaign, with opposition MPs accusing him of exploiting the temple project for political gain.
A Hindu nationalist, Mr Modi has sought to transform India from a secular democracy into a Hindu state during his nearly 10 years in power.
Monday’s pomp-filled display highlighted the extent to which the line between religion and state had eroded under the 73-year-old’s rule, ahead of elections scheduled for April and May, critics said.
“Prime ministers prior to Modi have also been to temples, been to other places of worship, but they went there as devotees,” said Nilanjan Mukhopadhyay, an author on Hindu nationalism.
“This is the first time that he went there as somebody who performed the ritual.”
India’s main opposition Congress party boycotted the ceremony alongside Hinduism’s four leading spiritual leaders, the Shankaracharyas, who said it was not being inaugurated in the proper manner outlined by Hindu scripture.
Mr Modi’s BJP has long vowed to build the temple and its construction has served as a symbol of the growing sectarian divisions between Muslims and Hindus, with the latter making up 80 per cent of India’s population of 1.4 billion.
The site has long been a religious flashpoint for the two communities, with the demolition of the mosque more than three decades ago triggering bloody riots across India that killed 2,000 people, mostly Muslims.
A 2019 Supreme Court ruling gave the land to Hindus and provided Muslims with a plot outside of Ayodhya to build a replacement mosque.
The fraught history is still an open wound for many Muslims, who see the construction of the temple as a testament to Mr Modi’s Hindu-first politics.
The former mosque, the Babri Masjid, was built by the-then ruling Mughal dynasty in the 16th century on the site of what Hindus say was an earlier temple.
Authorities expect 150,000 people to visit the new temple every day after it opens to the public on Tuesday.