Mother Earth, unable to bear the burden of sins committed by evil kings and rulers, appealed to Brahma, the Creator for help. Brahma prayed to the Supreme Lord Vishnu, who assured him that he would soon be born on earth to annihilate tyrannical forces.
One such evil force was Kamsa, the ruler of Mathura (in northern India) and his people were utterly terrified of him. On the day Kamsa's sister Devaki was married off to Vasudeva, an akashvani or voice from the sky was heard prophesying that Devaki's 8th son would be the destroyer of Kamsa. The frightened Kamsa immediately unsheathed his sword to kill his sister but Vasudeva intervened and implored Kamsa to spare his bride, and promised to hand over every new born child to him. Kamsa relented but imprisoned both Devaki and her husband Vasudeva.
When Devaki gave birth to her first child, Kamsa came to the prison cell and slaughtered the newborn. In this way, he killed the first six sons of Devaki. Even before her 8th child was born, Devaki and Vasudeva started lamenting its fate and theirs. Then suddenly Lord Vishnu appeared before them and said he himself was coming to rescue them and the people of Mathura. He asked Vasudeva to carry him to the house of his friend, the cowherd chief Nanda in Gokula right after his birth, where Nanda's wife Yashoda had given birth to a daughter.
He was to exchange his boy and bring Yashoda's baby daughter back to the prison. Vishnu assured them that "nothing shall bar your path".
At midnight on ashtami, the divine baby was born in Kamsa's prison. Remembering the divine instructions, Vasudeva clasped the child to his bosom and started for Gokula, but found that his legs were in chains. He jerked his legs and was unfettered! The massive iron-barred doors unlocked and opened up.
While crossing river Yamuna, Vasudeva held his baby high over his head. The rain fell in torrents and the river was in spate. But the water made way for Vasudeva and miraculously a five-mouthed snake followed him from behind and provided shelter over the baby.
When Vasudeva reached Gokula, he found the door of Nanda's house open. He exchanged the babies and hurried back to the prison of Kamsa with the baby girl. Early in the morning, all the people at Gokula rejoiced the birth of Nanda's beautiful male child. Vasudeva came back to Mathura and as he entered, the doors of the prison closed themselves.
When Kamsa came to know about the birth, he rushed inside the prison and tried to kill the baby. But this time it skipped from his hand and reaching the sky. She was transformed into the goddess Yogamaya, who told Kamsa: "O foolish! What will you get by killing me? Your nemesis is already born somewhere else."
In his youth Krishna killed Kamsa along with all his cruel associates, liberated his parents from prison, and reinstated Ugrasen as the King of Mathura