Lord Hayagreeva (Hayasirsha Swamy) is an incarnation of Sri Maha Vishnu as per Bhagavata Purana. The main purpose of Lord Vishnus Hayagriva incarnation was to recover Vedas from demons Madhu and Kaitabha. Goddess Shakti (Mother Goddess) blessed Lord Brahma with Vedas. He was supposed to create the Universe by looking into the Vedas as standard texts. Brahma created two demons, Madhu and Kaitabha, from two water droplets. Unfortunately, Madhu and Kaitabha had stolen the Vedas from Brahma.
Birth and Purpose of Lord Hayagriva Avatar
With out the Vedas, Brahma was not able to do his duties. He went to Goddess Shakti and prayed to her. She suggested him to worship Lord Vishnu to recover the Vedas. Brahma, as Shakti said, prayed to Lord Vishnu. Vishnu incarnated as Hayagriva and demolished the demons Madhuand Kaitabha and recovered Vedas. Thus, Hayagreeva became the protector of the Vedas.
There is one more popular legend about the birth and the purpose of Hayagrivas birth. With blessings of Goddess Shakti and using the Vedas, Brahma started to create the Universe. He became headstrong and wasnt caring any God. He behaved very furiously with all other Gods that he is the Supreme God and he creates the Universe. To make him realize the truth that he is not great and all the credit goes to the Vedas, Lord Vishnu made the demons Madhu and Kaitabha to steal the Vedas from Brahma.
Once Brahma realized the truth and worshipped him, Vishnu incarnated as Hayagriva and killed the demons to protect the Vedas.