Introduction
Hayagriva is an Asura who stole the Vedas from Brahma while he slept, in the account followed by the Bhagavata Purana in connection with the Matsya avatar. He shares his name, but not his identity, with Vishnu's own benevolent horse-headed form, also called Hayagriva, worshipped as a giver of knowledge.
This article covers only the demon; the reader should not confuse him with Vishnu's avatar of the same name.
The theft
At the end of one age, as Brahma slept between cycles of creation, an Asura named Hayagriva, called Somaka in some versions, stole the four Vedas as they slipped from Brahma's mouth, and hid with them in the depths of the ocean.
Recovery by Matsya
Vishnu, taking the form of the fish Matsya to save King Satyavrata (Manu) from the coming deluge, also dived into the ocean, found and killed Hayagriva, and recovered the Vedas, returning them to Brahma.
Distinct from Vishnu's Hayagriva
Vishnu himself has a separate, unrelated form also named Hayagriva, horse-headed and benevolent, worshipped as a god of knowledge and learning, particularly in Tamil Vaishnavism. The two figures share only a name; the Asura Hayagriva is not an avatar of Vishnu and has no connection to the god of learning beyond the coincidence of the title.