PM Modi, on a day-long visit to the state to attend various public functions, earlier landed in Mangaluru, about 80 km from Dharmasthala, and flew in a helicopter to this temple town.
The prime minister waved to the crowd, who chanted "Modi, Modi", as he stood at the entrance, before proceeding to offer prayers at the temple.
He was accorded a traditional welcome at the temple, where Dharmadhikari (hereditary administrator) D Veerendra Heggade took him around.
"I am happy that I got the opportunity to pray to Lord Manjunatha," PM Modi was quoted as saying in a tweet by the prime minister's office.
At Ujire, the prime minister attended a function of the Shri Kshetra Dharmasthala Rural Development Project, where he distributed Rupay cards and launched the 'Digitised SHG (self-help group) Member Transaction' and 'Preserve Mother Earth' campaigns.
The Dharmasthala temple is one of the renowned religious landmarks of south India with a history of over 800 years.
Get the latest election news, live updates and election schedule for Lok Sabha Elections 2019 on ndtv.com/elections. Like us on Facebook or follow us on Twitter and Instagram for updates from each of the 543 parliamentary seats for the 2019 Indian general elections.