As per Mahabharata, during the Kurukshetra war, all of the hundred sons of Gandhari were killed in the battle. Due to that, Gandhari had become very angry with Lord Krishna, and as a result, she cursed Krishna, that the entire Yadavas would be destroyed after 36 years. Similarly, after the completion of 36 years, severe clash occurred between the Yadavas, and they were killed by each other. On seeing this incident, Lord Balarama, had left his body through meditation, and went to Vaikunta.
Lord Krishna also wanted to leave his body, and hence he rested under a tree in a forest. At that time a hunter who mistakenly shot an arrow on the left leg of Lord Krishna, by thinking him to be a deer, was later realized that he had done a big mistake, and asked Lord Krishna to apologize him.
Lord Krishna had forgiven his mistake, and informed to Jara, that he was the mighty Vanara King Vali during the Treta Yuga, and he was killed by Rama. In order to bear the sin committed by Lord Rama, Krishna had to bear the pain caused by the arrow of Jara. Krishna blessed Jara and sent him to Indra Loka, and after some time, Krishna went to Vaikunta, with his own physical body.
With the end of Krishna avatar, Kali Yuga had started, and Kali Purusha started doing his evil acts to the people. But if the people divert their attention on worshipping Lord Krishna, then Kali Purusha would not give much disturbance to the devotees of Krishna.
The place where Lord Krishna had ended his avatar is the present day Bhalka Teerth, situated a few kilometres away from the Somnath temple. Pilgrims who visit the Somnath Temple are advised to visit the Bhalka Teerth and they can pay their respects to Lord Krishna and the noble hunter Jara. From the above incident, we can knew, that even if the divine avatars commit a sinful act, they also have to suffer for that.