The legend begins with the Mahābhārata. Barbarika also known as Khatushyamji was a grandson of Bhima. He was the son of Ghatotkacha (who in turn was son of Bhima) and Ahilavati. Even in his childhood, Barbarika was a very brave warrior. He learnt the art of warfare from his mother. God Shiva, pleased with him, gave him the three infallible arrows (Teen Baan). Hence, Barbarika came to be known by the appellation Teen Baandhaari, the "Bearer of Three Arrows". Later, Agni (the god of Fire) gave him the bow that would make him victorious in the three worlds.
When Barbarika learnt that battle between the Pandavas and the Kauravas had become inevitable, he wanted to witness what was to be the Mahābhārata War. He promised his mother that if he felt the urge to participate in the battle, he would join the side which would be losing. He rode to the field on his Blue Horse equipped with his three arrows and bow.
Krishna disguised as a Brahmin and stopped Barbarika to examine his strength. He baited Barbarika by mocking him for going to the great battle with only three arrows. On this, Barbarika replied that a single arrow was enough to destroy all his opponents in the war, and it would then return to his quiver. He stated that, the first arrow is used to mark all the things that he wants to destroy. On releasing the third arrow, it would destroy all the things that are marked and will then return to his quiver. If he uses the second arrow, then the second arrow will mark all the things that he wants to save. On using the third arrow, it will destroy all the things that are not marked. In other words, with one arrow he can fix all his targets and with the other he can destroy them.
Krishna then challenges him to tie all the leaves of the peepal tree under which he was standing with these arrows. Barbarika accepts the challenge and starts meditating to release his arrow by closing his eyes. Then, Krishna without the knowledge of Barbarika, plucks one of the leaf of the tree and puts it under his foot. When Barbarik releases his first arrow, it marks all the leaves of the tree and finally starts revolving around the leg of Krishna. For this Krishna asks Barbarika, as why was the arrow revolving around his foot? For this, Barbareek replies that there must be a leaf under his foot and the arrow was targeting his foot to mark the leaf that is hidden under him. The first arrow pricks Krishna's leg and mark the leaf that is hidden under Krishna's foot. This becomes a weak spot of Krishna. (When Krishna revives Abhimanu's son Parkishit, he looses half of his strength making him even more weaker. Later, a hunter by name Jara hits at Krishna's foot mistaking him for a deer leads to the death of Krishna. In other words, this weak spot on Krishna's foot was first created by Barbareek's arrow.)
Of course, the third arrow does collect all the leaves (including the one under Krishna's foot) and ties them together. By this Krishna concludes that the arrows are so infallible, that even if Barbarika is not aware of his targets, the arrows are so powerful that they can still navigate and trace all his intended targets. The moral of this incident is that, in a real battle field, if Krishna wants to isolate some one (for example: the 5 Pandava brothers) and hides them elsewhere in order to avoid them from being Barbarika's victim, then Krishna will not be successful as the arrows can still trace the target and destroy them. So, nobody will be able to escape from these arrows. Thus Krishna gets a deeper insight about Barbarika's phenomenal power.
Krishna then asks the boy whom he would favour in the war. Barbarika reveals that he intends to fight for the side whichever is weak. As Pandavas have only seven Akshouni army, when compared to Kauravas eleven, he considers that Pandavas are weak and hence wants to support them so that Pandavas will become victorious. But Krishna asks him, did he seriously gave a thought about the consequences before giving such a word to his mother (to support the weak side). Barbarika guesses that his support to the weaker side will make them victorious. Then, Krishna reveals the actual consequence of his word to his mother:
Krishna tells that whichever side he supports will only make the other side weak due to his power. Nobody will be able to defeat him. Hence, he is forced to support the other side that has become weaker due to his word to his mother. Thus, in an actual war, he will keep oscillating between the two sides, there by destroying the entire army of both sides and eventually only he remains. Subsequently, none of the side is victorious as he will be the only lone survivor.
The guised Krishna then sought charity from Babarika. Barbarika promised him anything he wished. Krishna asked him to give his head in charity. Barbarika was shocked. Perceiving that all was not as it appeared, he requested the Brahmin to disclose his real identity. Krishna showed Barbarika a vision of His Divine Form and Barbarika was thus graced. Krishna then explained to him that before a battle, the head of the bravest Kshatriya needs to be sacrificed, in order to worship/sanctify the battlefield. Krishna said that he considered Barbarika to be the bravest among Kshatriyas, and was hence asking for his head in charity. In fulfilment of his promise, and in compliance with the Krishna's command, Barbarika gave his head to him in charity.
Barbareek requested that he wanted to see the battle till its end, and his wish was granted. Thus on the 12th 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.