Hayagriva, meaning one with the horse's neck, was the son of 'Kashyap Prajapati'. Through his great penance he had managed to obtain boon from the Goddess that he could only be killed by another "Hayagriva". The boon instilled in him a sense of being invincible and as a result he started harassing the Devas realising that they could not kill him. The Devas asked for Vishnu's help but a long battle with Haygriva bore no fruit and it only left Vishnu tired and drained. Vishnu then proceeded to Vaikuntha Dham to rejuvenate himself and once there he went into meditation in padamaasna (a yoga posture) with his head supported by the upper end of his taught bow. The Devas meanwhile aggrieved by Haygriva again approached Vishnu for help but were unable to rouse him from the state of deep meditation. The Devas then took the help of the Termites in rousing Vishnu who gnawed away the string of the bow upon which Vishnu was resting. The snapping of the string of the bow produced such a resonant sound that the whole universe trembled and the string on being snapped, lashed out with such force at the head of Vishnu that it was severed from the rest of its body.
The sight of beheaded, Vishnu filled the Devas with horror and mortification and out of sheer panic they started praying to the Goddess for help. Goddess pleased with their prayers told the Devas that they need not fear as no incident in this universe is without some purpose. She then told them of her boon to Asura Haygriva and asked them to attach the head of a horse to Vishnu so that he in the guise of "Haygriva" could kill the Asura Hayagriva.
Thus, Vishnu Taking the form of the "one with the head of a horse" entered into a battle with the Asura and eventually killed him with the grace of the goddess.