Barbarika (Belarsen) was the son of Ghatotkacha, and the grandson of Bhima. He was a brilliant warrior, and was given a boon of three magical arrows from Lord Shiva (Teen Baan), which is why he's also known as Teen Baandhari.
When the Kurukshetra was about to begin, Belaarsen promised his mother he'd participate in the war if he felt the fancy, only to aid the losing side, and wished to watch the war as a spectator otherwise.
During Kurukshetra, Lord Krishna went around asking people how long they'd take to end the war on their own. Even mighty warriors like Arjuna estimated they'd take 28 days, however Belaarsen promised Krishna he could end the war in a minute.
Krishna, perturbed, visited Belaarsen disguised as a Brahmin. He asked Belaarsen to demonstrate his arrows and realized they were infallible. The first arrow Belaarsen fired would mark all the things he wished to destroy. The second, if used, would mark all the things he wished to save. The third, finally, would destroy all the things the first had marked. To test out these arrows, Krishna asked Belaarsen to shoot down all the leaves from a nearby tree. However,he kept a leaf hidden under his foot. Belaarsen, upon firing his first arrow, saw it mark all the leaves on the tree and then prick Krishna's foot. (This is another theory why Krishna's foot was a weak spot, along with Durvasa's curse)
Seeing this, Krishna realized it wasn't in his power to hide anything from Belaarsen's arrows, and the Pandavas wouldn't be safe from him.
It dawned upon him that this man could single-handedly destroy the world if he so wished to, and he decided to nip this threat in the bud.
First, he explained to Belaarsen that if he chose to aid the losing side, the other side would start losing, and he'd be oscillating between the two sides and eventually be the only man left. He was also aware that Belaarsen was a generous man, and never refused to grant someone a boon, so he asked Belaarsen for his head as a sacrifice, to anoint the battlefield in the blood of the bravest Kshatriya. Belaarsen, obviously, grew suspicious of the Brahmin, and asked him to reveal his true self. Upon seeing Krishna in his divine glory, Belaarsen agreed to sacrifice himself on the condition he could watch the war. Krishna agreed, lopped his head off, and mounted it on a pole next to the battlefield.
Eventually, after Kurukshetra ended, the Pandavas were arguing over who had been the best warrior. Krishna suggested they go and aasked Belaarsen. On being questioned, he said "All I could see were two things. One, a divine chakra spinning all around the battle field, killing all those who were not on the side of Dharma. The other was Goddess Mahakali, who spread out her tongue on the battle field and consumed all the sinners as her sacrifice".
Hearing this, the Pandavas realized it was Lord Narayan, and Goddess Mahamaya who had cleansed the world with this war, and they had been mere instruments of this divine cleansing.