Bhagavad Gita Chapter 08, Text 06

Bg 8.6

yam yam vapi smaran bhavam
tyajaty ante kalevaram
tam tam evaiti kaunteya
sada tad-bhava-bhavitah

Word for word: 
yam yam — whatever; va api — at all; smaran — remembering; bhavam — nature; tyajati — gives up; ante — at the end; kalevaram — this body; tam tam — similar; eva — certainly; eti — gets; kaunteya — O son of Kunti; sada — always; tat — that; bhava — state of being; bhavitah — remembering.

Translation by His Divine Grace A. C. Bhaktivedanta Swami Srila Prabhupada:
Whatever state of being one remembers when he quits his body, O son of Kunti, that state he will attain without fail.

Purport by His Divine Grace A. C. Bhaktivedanta Swami Srila Prabhupada:
The process of changing one’s nature at the critical moment of death is here explained. A person who at the end of his life quits his body thinking of Krishna attains the transcendental nature of the Supreme Lord, but it is not true that a person who thinks of something other than Krishna attains the same transcendental state. This is a point we should note very carefully. How can one die in the proper state of mind? Maharaja Bharata, although a great personality, thought of a deer at the end of his life, and so in his next life he was transferred into the body of a deer. Although as a deer he remembered his past activities, he had to accept that animal body. Of course, one’s thoughts during the course of one’s life accumulate to influence one’s thoughts at the moment of death, so this life creates one’s next life. If in one’s present life one lives in the mode of goodness and always thinks of Krishna, it is possible for one to remember Krishna at the end of one’s life. That will help one be transferred to the transcendental nature of Krishna. If one is transcendentally absorbed in Krishna’s service, then his next body will be transcendental (spiritual), not material. Therefore the chanting of Hare Krishna, Hare Krishna, Krishna Krishna, Hare Hare/ Hare Rama, Hare Rama, Rama Rama, Hare Hare is the best process for successfully changing one’s state of being at the end of one’s life.