The legend of Shyam Baba can be traced back to the medieval Mahabharata. Barbareek was the son of the great Pandava brother - Bhim and Nag Kanya - Ahilawati. Barbareek, from his childhood was very brave and a great warrior. He learnt the art of fighting from his mother. Lord Shiva, pleased with him, gave him the three infallible Arrows (Teen Baan) and Agni Dev (Fire God) gave him the Bow, which would make him victorious in the three worlds.
The battle of Mahabharata was inevitable between the Pandavas and Kauravas, and having got the news, Barbareek wanted to witness the great war. He promised to his mother, that if he felt the urge, to participate in the battle, he would join the side which would be losing. He rode on the Blue Horse (Leela Ghora) equipped with the three arrows and the bow. The omnipresent Lord Krishna, disguising himself as a Brahmin, stopped Barbareek to examine his strength. He even tried to mock Barbareek saying that he was going to the great battle with only three arrows.
On this, Barbareek replied that only one arrow was enough to destroy all the enemies in the war, and it would then return to his quiver. If all the three were used, it would create havoc in the three worlds. Lord Krishna challenged him to tie all the leaves of the peepal tree under which he was standing, with one arrow. Barbareekaccepted the challenge, removed one arrow from his quiver and released it from his bow.
The arrow tied all the leaves together within moments. But Lord Krishnahad one leaf under his foot. The arrow then started revolving around his foot, and he asked the boy, whom would he favour in the war. Barbareek reiterated that he would fight for the side which loses. Lord Krishna knew that defeat of Kauravas was inevitable, and if this vrave boy joins them, the result would be in their favour.
The Brahmin (Lord Krishna) then wanted charity from the boy. Barbareek promised him anything he wished. Lord Krishna asked him to give his head in charity. The boy was shocked, but he maintained his promise. He requested the Brahmin to disclose his identity. Lord Krishna showed him his divine form.
He explained to Barbareek that before the battle, in order to worship the battlefield, head of the bravest Kshatriya needs to be sacrificed. And he considered Barbareek to be the bravest, and hence asked for his head in charity.
Barbareek requested that he wanted to see the battle till its end, and his wish was granted. Thus on the12th day of Shukla Paksha of Falgun month, he gave his head to Lord Krishna (SHISH DAAN). The head was placed atop a hill near the battlefield from where, Barbareek could watch the whole battle.
When the battle was over and Pandavas having won, they argued amongst themselves as who was responsible for victory. At this, Lord Krishna suggested that Barbareek\'s head had watched the whole battle, and who else would be a better judge. Barbareek\'s head suggested that it was Lord Krishna who was responsible for the victory, his advice, his presence, his gameplan had been crucial. He could see only the Sudarshan Chakra revolving around the battlefield which was hacking the Kaurava army to pieces and Draupadi assuming the fearful form of Mahakali Durga was drinking bowl after bowl of blood and was not allowing even one drop of blood to fall on the earth.
Lord Krishna, pleased with Barbareek\'s great sacrifice, granted him the boon that when Kaliyug descends, he would be worshipped by the name of Shyam in his form. His devotees would be blessed just by pronouncing his name from the bottom of their hearts.
His head was then buried in Khatu. Milk started to flow out of a cow\'s udder when she reached the spot. Later, the place was dug up, and the head appeared. The head was handed over to a Brahmin who worshipped the head for many days. The King of Khatu had a dream where he was inspired to build a temple and install the head. Subsequently, a temple was built and the head "SHISH" was installed on the 11th day of Shukla Paksha of Kartick month.