Modi paid the unscheduled visit to the Gurudwara Rakabganj temple on Sunday. He prayed at the temple, interacted with Sikh religious leaders and obliged visitors seeking to take pictures with him.
Officials said they made no special arrangements or traffic barriers to restrict people's movement for the visit.
“I felt extremely blessed,” Modi wrote on Twitter.
During the visit, people called on the premier to also pay a visit to the site of a protest on the suburbs of New Delhi, where farmers from around the nation have set up makeshift camps for weeks to protest the newly passed farm bills that farmers say will ravage their livelihoods.
Protesting farmers, mainly from Sikh-dominated Punjab and neighboring Haryana, have blocked highways into New Delhi for the past three weeks demanding a repeal of the laws.