Nag Panchami is also connected with the following legend of Krishna .
On Nag Panchami day the victory of Krishna over the Kaliya snake is commemorated. For this reason Krishna is known as “Kaliya Mardan”. Snakes are believed to like milk. As this is the day of the serpents, devotees pour milk into all the holes in the ground around the house or near the temple to propitiate them. Sometimes, a small pot of milk with some flowers is placed near the holes so that the snakes may drink it. If a snake actually drinks the milk, it is considered to be extremely lucky for the devotee.
Naga Panchami is observed indifferent ways in different parts of India . It is one of the most ancient fasts, and finds mention in the Puranas. It is believed to be one of the most auspicious days of the entire year. According to the Bhavishya Purana, when men bathe the snakes called Vasuki, Takshaka, Kaliya, Manibhadra, Airavata, Dhritarashtra, Karkotaka and Dhananjaya with milk on the fifth day of the bright fortnight of Shriven, they ensure freedom from danger for their families.
How the snakes were saved - A Hindu mythology
(Story from the Hindu epic Mahabharata)
Once upon a time, a great king Parikshit died due to the bite of a snake called Takshak. To seek revenge of his father's death Janmejay, who is also known as the first ruler of the era of Kalyug (the era of 'Kali') performed a Nag Yajna, which would kill all snakes and make the universe free of snakes.
Due to the effect of this Yajna by Janmejaya many snakes died. Very few were left alive.
Vasuki, the King of the snake, was extremely worried. He went to his sister Jaratkaruand said, "Sister, I feel as if I am burning. I am feeling faint and my resistance to the fire of the Yajna is weakening. I am being pulled towards the fire and I feel as if very soon I shall be drawn into the fire as well. I was anticipating that such an incidence might happen, and it is for this day only that I had married you to Rishi Jaratkaru. Now, you are the only one who can save us. According to the prophecy of Lord Brahma, only your son Aasteek will be able stop this Yajna. I know that he is still a boy, but he is a great scholar of the Vedas and is loved by all his elders. I request you to ask him to save our lives now otherwise all the snakes will disappear from earth."
Hearing these words Jaratkaru went to her son and requested him to save the lives of the snakes. Aasteek went back to Vasuki and said, "O, King of the snakes, do not fear. I shall help you to get rid of the curse. I shall go to King Janmejaya and impress him with my knowledge and request him to stop the yajna."
Thus assuring Vasuki, Aasteek left for the venue of the Yajna. When he reached there he saw all the eminent people sitting there. But he was not allowed to go inside by the sentries. Aasteek then started to sing hymns in praise of the Yajna so that he would be allowed inside.
The sweet voice of Aasteek reached Janmejaya and he gave him permission to attend the Yajna and called him inside the premises. Once inside, Aasteek sang praises of all those who were present there and this pleased the congregation.
Pleased, Janmejaya thought that he should grant the boy a wish as he was mature for his years and a great scholar. He asked the advice of the wise sages present there what he should do with this young boy. All the wise men unanimously declared that since the boy was a brahmin and a scholar at that, he was venerable.
Having obtained the counsel of the wise men, Janmejaya then requested all those learned sages to ensure that his Yajna was successful and that soon Takshak (the snake who had bitten his father, Parikshit), should fall into the fires of the Yajna and die. The wise men at the Yajna told Janmejaya that Takshak had gone to Indra (the King of the Gods) and Indra had promised full protection to Takshak.
Upon hearing this Janmejaya requested the sages and priests to chant such powerful mantra that even Indra would be powerless before it and would fall into the fire with Takshak. The priests started chanting most potent mantras and soon both Takshak along with Indra were pulled towards the fire. Afraid that he would also die, Indra left Takshak to fend for himself. Takshak started to be pulled towards the fire with each passing minute.
Now that Janmejaya was assured that his enemy would die, he turned to Aasteek and requested him to ask for anything that he wished for. Aasteek, seeing that Takshak would soon fall into the fire, took advantage of the situation and asked Janmejaya to stop the Snake Yajna so that the snakes who were left could survive. Janmejaya tried his best to persuade Aasteek to ask for anything other than this. Aasteek was not one to give up easily, he asked Janmejaya to stop the Yajna and also reminded him that he could not refuse what he had promised. He said that he was asking for this because he had to save his mother's clan.
Finally, Janmejaya had to relent and he stooped the Yajna putting the fires out. Meanwhile Aasteek stopped the rapid descent of Takshak towards the fire by chanting counter mantras. Takshak was relieved andd grateful that his life was saved and he thanked Aasteek.
Having succeeded, Aasteek then went to Vasuki, his Uncle and Jaratkaru, his mother and narrated the whole incident to them.
The court of Vasuki, the king of the snakes was full of the snakes who had survived the ordeal of the Yajna. They collectively blessed Aasteek and asked him to ask them for a boon. Aasteek said, "I will chant three mantras. I want a boon that that anyone who chants these three mantras at least once a day, should be spared death by a snake bite".
He then chanted the three Mantras called Asit, Aartiman and Suneeth. The snakes granted Aasteek his wish and it is believed that if someone chants one of these mantras even once a day, he will have nothing to fear from the snakes.
The Mantras are as follows:
"Yo Jaratkaruna Jato Jaratkarau Mahayashah;
Aasteekah Sarpsatray vah Pannagaan Yobhyarakshat;
Tam Samarantam mahabhaga na Mam Hinsitumarhatha."
"A great sage called Aasteek was born to Saint Jaratkaru and the snake woman, Jaratkaru. Aasteek saved the snakes from the Snake Yajna. So all of you holy and lucky snakes, I am remembering him. Please do not bite me."
"Sarpapsarpa Bhadram Te Gachcha Sarpa Mahavisha;
Janmejasya Yajnante Aasteekvachanam Smara."
"Hey, all ye holy and poisonous snakes! Please go away. May you be blessed. Remember all that Aasteek said at the end of the Snake Yajna of Janmejaya and go away now."
"Aasteekasya Vachah Shrutva Yah Sarpo na Nivartate;
shatadha bhidyate Murdhina Shinshavrikshaphalam Yatha."
"The snakes who do not return even after hearing the words of Aasteek, their hoods will be split into hundreds of pieces like the fruit of the Shisham tree"
This is how Aasteek stopped the Snake Yajna and saved the snakes from annihilation.