Shri Guru Nanak Dev Ji along with Bhai Mardana Ji reached Hasan Abdal in Baisakh Samwat 1578 B.K. corresponding to 1521 ACE in the summer season. Under a shady cool tree, Guru Nanak and Bhai Mardana started reciting Kirtan and their devotees gathered around. This annoyed a local saint, Shah Wali Qandhari. According to legend, Bhai Mardana was sent three times to Shah Wali Qandhari by (Guru Nanak) so that he would provide him with some water to quench his thirst. Wali Qandhari refused his request and was rude to him. In spite of this, Mardana still very politely stuck to his demand. The Wali remarked: “Why don’t you ask your Master whom you serve?”
Mardana Ji went back to the Guru in a miserable state and said “Oh lord! I prefer death to thirst but will not approach Wali the egoist.”
The Guru replied “Oh Bhai Mardana ji! Repeat the Name of God, the Almighty; and drink the water to your heart’s content.”
The Guru put aside a big rock lying nearby and a pure fountain of water sprang up and began to flow endlessly. Bhai Mardana quenched his thirst and felt grateful to the Guru.
On the other hand, the fountain of Shah Wali Qandhari dried up. On witnessing this, the Wali in his rage threw a part of a mountain towards the Guru from the top of the hill. The Guru stopped the hurled rock with his hand leaving his hand print in the rock.
Observing that miracle, Wali became the Guru’s devotee.
This holy and revered place was named Panja Sahib by Hari Singh Nalwa, the most famous general of the Kingdom of the Sikhs. He is credited with having built the first gurdwara at this place.