Baba Guru Nanak along with Bhai Mardana 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 Wali Qandhari but he was helpless.
According to legend, Bhai Mardana was sent three times to 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 ironically remarked : Why don't you ask your Master whom you serve?
Mardana 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 ! 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 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.