There are many versions of the myth of Matsya in the Puranas, with many interesting paradoxes and twists in the story line. Even the names of principle characters change. But the essentials of the myth speak of an avatara of Vishnu coming down to earth at the end of an age in order to save the world from spiritual darkness. Vishnu had to save both the first human being, the sage Satyavrata (who was to become the Manu, the first human, of the next or seventh manvantara) and save the Vedas.
So Vishnu incarnated as a tiny fish, and Satyavrata found him. When this tiny creature spoke to him, expressing its fear of being in the pond, the sage took him home in a water jar (kamandalu). The fish kept growing, so that Satyavrata had to move it to larger and larger bodies of water until he finally placed it in the ocean. Then he recognized the fish as Vishnu, lord of the universe. At that pointMatsya told Satyavrata of the imminent end of the age with its resulting dissolution (pralaya), and told him to prepare by saving animals and plants. Satyavrata must also save the seven sages (sapta-rishis). He gathered everything into a boat. When the flood began, Matsya appeared and threw them a rope, which, in some versions, was said to be the great serpent Ananta.
While pulling the boat, Matsya instructed the future Manu and the Rishis in the wisdom of the Vedas. This involved rescuing the Vedas, which had fallen from the mouth of Brahma when he fell asleep at the beginning of the involution.
The great demon Hayagriva had been waiting for his chance to steal the Vedas for the demons (asuras), and thus the entire next age would have been without the scriptures. Matsya defeated Hayagriva and saved the Vedas for the world, as each incarnation of Vishnu has always done.
The details of this myth vary slightly in different Puranas. In one, the seventh Manu, Vaivasvata, was the hero saved from the deluge of destruction at the end of a cosmic cycle (a day of Brahma). Vishnu came as a small fish, which Vaivasvata Manu found and saved, only to be responsible for moving it to larger bodies of water as it grew. Finally only the ocean could hold Matsya. Then Manu realized that this marvelous fish must be Vishnu, lord of the universe, whom he worshipped. Matsya warned Manu of the flood and had him tie a ship to the fish’s great horn. Thereby the ship was protected from the great storms until the flood subsided.
In the Bhagavata Purana the demon Hayagriva stole the Vedas as Brahma ended the age and began his sleep. It was Vishnu as Matsya who saved the Vedas, the sage Satyavrata, the seven rishis, and a boatload of animals and seeds for plants, for the beginning of the next age. During the deluge of destruction (the night of Brahma), Vishnu as Matsya instructed Satyavrata and the sapta-rishis in the highest wisdom so that it would not be lost in the coming kalpa.