The prophet Muhammad, prior to his call to prophethood as a messenger of Allah, was on a retreat in a cave near the city of Mecca. There he is believed to have encountered the angel Gabriel, an encounter, according to the earliest biography penned on the prophet’s life by Quranic exegete and historian Ibn Ishaq, that was of great distress to the prophet. According to Ibn Ishaq, during this angelic encounter Muhammad passed out, and while unconscious the angel throttled him into submission, and evidently so hard as to make him feel he was near the point of death. This was Allah’s first means of providing revelation to Muhammad who would soon become the messenger of Allah.
However, in order to learn why the prophet desired to kill himself one needs to consider three important Islamic texts which convey this information: Ibn Ishaq, Al-Tabari, and Al-Bukhari. According to Ibn Ishaq’s biography Sirat Rasul Allah,
‘[Muhammad said,] “So I read it, and he departed from me. And I awoke from my sleep, and it was as though these words were written on my heart. Now none of God’s creatures was more hateful to me than an (ecstatic) poet or a man possessed: I could not even look at them. I thought, Woe is me poet or possessed—Never shall Quraysh say this of me! I will go to the top of the mountain and throw myself down that I may kill myself and gain rest. So I went forth to do so and then) when I was midway on the mountain, I heard a voice from heaven saying, “O Muhammad! thou art the apostle of God and I am Gabriel.”’ (p. 106)
Al-Tabari, a further important historian and Quranic exegete, in his expansive work Tarikh al-Rusul wa al-Muluk informs readers that,
‘He (Muhammad) said: I had been thinking of hurling myself down from a mountain crag, but he appeared to me, as I was thinking about this, and said, “Muhammad, I am Gabriel and you are the Messenger of God.” Then he said, “Recite!” I said, “What shall I recite?” He took me and pressed me three times tightly until I was nearly stifled and was utterly exhausted; then he said: “Recite in the name of your Lord who created,” and I recited it. Then I went to Khadijah and said, “I have been in fear for my life.” (Volume VI, p. 68)
A third important text is from Sahih al-Bukhari which Muslims deem to be the most reliable and trustworthy hadith tradition. According to Al-Bukhari 6982,
“…after a few days Waraqa died and the Divine Revelation was also paused for a while and the Prophet became so sad as we have heard that he intended several times to throw himself from the tops of high mountains and everytime he went up to the top of a mountain in order to throw himself down, Jibril would appear before him and say, “O Muhammad! You are indeed Allah’s Messenger in truth”, whereupon his heart would become quiet and he would calm down and would return home. And whenever the period of the coming of the Revelation used to become long, he would do as before, but when he used to reach the top of a mountain, Jibril would appear before him and say to him what he had said before.’
These three sources are the most important ones for answering this question. So then what can one learn from them? At least three reasons for why the prophet wished to kill himself are immediately apparent. The death of Waraqa, the cousin of Muhammad’s wife Khadijah, was likely painful to him, and her death coupled with the fact that divine revelation had halted for a while was enough to make the prophet so upset as to want to hurl himself from a mountain. It is important to note that from Sahih al-Bukhari we learn that the prophet actually attempted to carry out his plan multiple times but was stopped by the angel Gabriel. It wasn’t merely conceptualized and left as a thought but rather acted upon. Furthermore, we learn from Al-Tabari that the prophet was so afflicted by his experience with the angel Gabriel that he feared for his life, and even went to his wife Khadijah for comfort. According to Ibn Ishaq, the earliest source, Muhammad tried to kill himself because he believed he was possessed by an evil spirit. It is quite difficult to determine which of these explanations are true although it is possible that they all are.