Hindu mobs demolished a medieval mosque there in 1992, saying it was built on the ruins of a temple for Lord Ram, a revered deity.
Hindus and Muslims claimed ownership over the site for decades. Last year, the top court gave the site to Hindus, ending a decades-long legal battle.
The inauguration comes amid a massive surge in coronavirus cases in India.
The dispute, which goes back more than a century, has been one of India’s thorniest court cases. The Supreme Court gave Muslims another plot of land in the city to construct a mosque.
Mr Modi laid a symbolic silver brick in the sanctum sanctorum, or innermost sanctuary, of the site as scores of devotees watched the event on giant screens across the city.
Due to Covid-19, the venue and surrounding areas were cordoned off, and access was restricted to invitees only.
BBC Hindi’s Sarvapriya Sangwan, who is in Ayodhya, says crowds of people gathered outside the venue, and cheered when they spotted Mr Modi on his way to the site.
Speaking soon after he laid the foundation stone, Mr Modi began with the words, “Jai Siya Ram”, instead of the more popular slogan, “Jai Shri Ram”, which has become a rallying cry for right-wing Hindus in the country.