The first story
1) In Vedic litarature :-In Vedic literature incarnation as Hayagriva is attributed not to Visnu, but to Yajna. But the Taittiriya aranyaka depicts Yajna as a protoform of Visnu. The inference that may be drawn from the above is that the root of the Hayagriva story detailed in Vedic and Puranic literature is one and the same.
About the Hayagriva incarnation the Pancavimsabrahmana contains the following story.
Agni, Indra, Vayu and Yajna (Visnu) once began a yajna on the understanding that the havirbhaga obtained from it should be divided among all the Devas. But, in violation of the agreement, yajfia left the place carrying away the whole Yajnabhaga with him, and he drove back the Devas who followed him with the help of the bow presented to him by Devi. Finally the Devas got the string of the bow bitten off by termites and the bow which got straightened up cut off yajfia’s head. Yajna then apologized for his offence and then the devas got the Asvinidevas to fix the head of a horse to the trunk of Yajna. (Pancavimsabrahmana 7, 5, 6; Taittiriya aranyaka 5, 1; Taittiriya Samhita, 4-9, 1).
The second story
2) In Puranic literature. The above story is told in Skanda Purana with slight modifications as follows :-
Once Brahma and other Devatas conducted a test as to which one amongst them was the greatest, and when it became evident tha tMahavisnu was, in every respect, superior to all the others Brahma cursed that Visnu should lose his head. Visnu, who got thus bereft of his head attended a yajfia conducted by the Devas with the head of a horse attached to his trunk. After the yajna was over he went to dharmaranya and did tapas there and by the blessings of Siva got back his former head instead of that of the horse.
The third story
The Lord appeared as the Hayagriva incarnation in a sacrifice performed by Brahma. He is the personified sacrifices, and the hue of His body is golden. He is the personified Vedas as well, and the Supersoul of all demigods. When He breathed, all the sweet sounds of the Vedic hymns came out of His nostrils.
At the end of each kalpa, when the demon Ajana steals the Vedic knowledge, Lord Hayagriva appears and preserves it. Then He delivers it to Lord Brahma
The Lord appeared as Hayagriva, with the head of a horse. He killed two demons known as Madhu and Kaitabha, who were full of the modes of passion and ignorance. For this reason, all the great saints accept his Forms as transcendental, untinged by material qualities.