How did Lord Krishna end His pastimes on earth?
Krishna is the eternal Supreme Person. His body is always spiritual, meaning that it is composed of eternity, knowledge, and bliss, whereas our bodies are temporary and made of gross matter. Just as the self is eternal, the supreme self is also. Krishna is always existing; He never dies, and unlike us He has no material body.
However, for the purpose of bringing His earthly activities to a dramatic close, He created an illusory display that made it appear as though He "died" after being struck in the foot by an arrow shot by a lone hunter in the forest. Of course, during His time on earth He was undefeated by any man, demon, demigod, or by any astronomical number of any of these. On the contrary, Krishna appeared specifically to diminish the world's unnecessary military buildup, and personally killed uncountable warriors in battle. Thus, His leaving the world after apparently being shot in the foot with a single arrow by a lone forest hunter was certainly an anomaly, and most clearly a situation of His own choosing.
His transcendental body can never be harmed or killed, but Krishna played the part of a human being in this world just to bewilder the atheists, who would never accept Him as He is—as the Supreme Personality of Godhead—anyway. He orchestrated His own departure from this world to serve the same purpose.
He doesn't interfere with anyone's free will. If we wish to disbelieve in His supremacy, He allows us to think whatever we like. For this reason, he created an illusory material body that was apparently "slain," just so that the most stubborn of atheists could point to this incident as "proof" that He is not supreme.
The Srimad-Bhagavatam, eleventh Canto, chapters 30-31 contains a description of the events surrounding Krishna's final moments on this planet, along with commentaries by various acharyas, which further explain this peculiar pastime.