The story of Krishna and Kāliya is told in the sixteenth chapter of the Tenth Canto of the Bhagavata Purana.
The proper home of Kāliya was the island of Ramaṇaka, but he had been driven away from there in fear of Garuḍa, the foe of all serpents. Garuḍa had been cursed by the yogi Saubhari dwelling at Vrindavan so that he could not come to Vrindavan without meeting his death. Therefore, Kāliya chose Vrindavan as his residence, knowing it was the only place where Garuḍa could not come.
Once, the sage Durvasā came as a guest and was served by Rādhā. After this episode, Rādhā took a walk across the river Yamunā and became terrified upon seeing the giant serpent. She fled to Vrindavan where she informed the people that she had seen a giant serpent in a river. Lord Krishna was very angry upon hearing this and wanted to teach a lesson to Kāliya as he had troubled his Rādhā. He went to the river Yamunā searching for Kāliya, who upon seeing Krishna, coiled around Krishna’s legs and constricted him.
The Gokul people came to see that Krishna was in the river. Yaśodā was afraid of the snake and ordered Krishna to return at once. Meanwhile, Kāliya attempted to escape, but Krishna stomped on his tail and warned him to not trouble anyone again before returning to the people. The next day, Krishna was playing a ball game across the Yamuna with Rādha and friends. After the ball fell into the Yamunā, Rādhā tried to retrieve it, but Krishna stopped her and offered to do so. When he went into the Yamunā, Kāliya constricted him and pulled him into the Yamunā.
The Gokul people heard the commotion and all the people of Nandagokula were concerned and came running towards the bank of the Yamunā. They heard that Krishna had jumped into the river where the dangerous Kāliya was staying. At the bottom of the river, Kāliya had ensnared Krishna in his coils. Krishna expanded himself, forcing Kāliya to release him. Krishna immediately regained his original form and began to jump on all of Kāliya’s heads so as to release the poison in the snake so that he could no longer pollute the Yamunā.
Krishna suddenly sprang onto Kāliya’s head and assumed the weight of the whole universe, beating him with his feet. Kāliya started vomiting blood and slowly began to die. But then Kāliya’s wives came and prayed to Krishna with joined palms, worshiping him and praying for mercy for their husband. Kāliya recognized the greatness of Krishna and surrendered, promising he would not harass anybody again. Krishna pardoned him after performing a final dance upon his head. After the performance, Krishna asked Kāliya to leave the river and go to Ramaṇaka island, where he promised that Kāliya would not be troubled by Garuḍa.
The people who had gathered on the banks of Yamunā were terrified, beholding the water that had changed to a poison colour. Krishna slowly rose up from the bottom of the river while dancing on Kāliya’s head. When the people saw Krishna, everyone was happy and they danced ecstatically upon Kāliya. At last, Kāliya was pushed into Pātāla where he is said to reside to this day.