According to the legend and the mythological stories it is said that during the war of Mahabharata, Barbarik the grandson of Bhim came to Lord Krishna and Pandavas and requested them to fight from their side. Barbarik was very courageous and brave since he was blessed with three bow of power which would win him the victory over three world of Power. Barbarik decided that he will fight for the side that would be losing in the war. In order to prevent that Lord Krishna played a trick, he took a false appearance of Brahmin in order to test his power and play a joke that he is taking just three bows to win the battle. After hearing that Barbarik answer the Brahmin that his one bow can destroy the all enemy in the war. Hearing that Lord Krishna with his trick asked him to tie all the leaves of peepal under his foot, his realised the bow with the quiver. Lord Krishna had one leaf under his foot the bow started to revolve around him. Then again Brahmin (Lord Krishna) asked him that to whom he would favour in the war. He stated that he will fight with the side who losses, Hearing that the Brahmin asked for daan from Barbarik. The great brave boy told him that he would give anything what he wants. Lord Krishna asked him to give his head in daan. The brave Barbarik chopped his head and gave it to Brahmin. On this Lord Krishna got impressed by the boy courage and sacrifice and blessed him with two boons. First that he would be able to see the war as his head was placed on a hill which Lord Krishna it. Secondly he will be worshiped as Lord Shyam in Kalyug.
Many years latter his head got buried in that hill. Then prolonged period his head was dug up many years the Bramins used to worship it. Latter a temple was made which is now known as Khatu Shyamji Temple. Each year many devotees come to over pilgrimage to this holy place of Lord Krishna.