Short answer
The Prophet ﷺ told us not to wish for death because of a hardship, so it is disliked (makruh), not a sign that you have left Islam. If you feel it, he taught a better dua: "O Allah, keep me alive while life is better for me, and take me when death is better for me." If you are thinking of ending your life, contact emergency services or a crisis line now.
Wishing for death because of worldly harm, such as illness, pain or poverty, is makruh. Wishing for it out of fear for one's religion in a time of trial, or longing to meet Allah, or asking for martyrdom, is not blameworthy.
The four schools agree on this.
Explanation
If you are in danger right now, please call your local emergency number or a crisis line, or go to the nearest emergency department. In the US you can call or text 988. In the UK and Ireland, Samaritans are on 116 123. Tell someone you trust how you feel today.
The Prophet ﷺ said: let none of you wish for death because of harm that has befallen him. If he must, let him say, "O Allah, keep me alive as long as life is better for me, and take me when death is better for me." This hadith is gentle. It does not call the person a sinner or weak. It turns a heavy wish into a dua that hands the matter back to Allah, who knows what is best.
Why is the wish itself discouraged? A believer's life is a chance to gain reward. Every pain, worry and illness wipes away sins, and patient days are written as good deeds. The Prophet ﷺ also said that a believer's affairs are all good, in ease and in hardship. Wishing to cut that short closes a door that is still open.
Scholars say some wishes are different. Fearing for your faith in a time of great trial, longing to meet Allah, or asking to die as a martyr is not blameworthy. Maryam said in labour, "I wish I had died before this," which scholars explain as the cry of someone in great distress about her honour.
If the wish keeps coming back, it is often a sign of depression or exhaustion, not of weak faith. Please speak to a doctor or counsellor; that is not a lack of trust in Allah. See suicidal thoughts and depression and iman, and the dua for hardship.
The evidence
Quran, Surah Maryam 19:23
فَأَجَآءَهَا ٱلْمَخَاضُ إِلَىٰ جِذْعِ ٱلنَّخْلَةِ قَالَتْ يَٰلَيْتَنِى مِتُّ قَبْلَ هَٰذَا وَكُنتُ نَسْيًۭا مَّنسِيًّۭا ﴿٢٣﴾
And the pains of childbirth drove her to the trunk of a palm tree. She said, "Oh, I wish I had died before this and was in oblivion, forgotten."
Maryam's words in labour, which scholars explain as distress rather than objection to Allah's decree.
Quran, Surah Az-Zumar 39:53
۞ قُلْ يَٰعِبَادِىَ ٱلَّذِينَ أَسْرَفُوا۟ عَلَىٰٓ أَنفُسِهِمْ لَا تَقْنَطُوا۟ مِن رَّحْمَةِ ٱللَّهِ ۚ إِنَّ ٱللَّهَ يَغْفِرُ ٱلذُّنُوبَ جَمِيعًا ۚ إِنَّهُۥ هُوَ ٱلْغَفُورُ ٱلرَّحِيمُ ﴿٥٣﴾
Say, "O My servants who have transgressed against themselves [by sinning], do not despair of the mercy of Allah. Indeed, Allah forgives all sins. Indeed, it is He who is the Forgiving, the Merciful."
Hope in Allah's mercy remains in every hardship.
Sahih al-Bukhari 5671
Sahih... لا يتمنين أحدكم الموت من ضر أصابه ...
"Let none of you wish for death because of harm that has befallen him."
Wishing for death because of hardship is discouraged.
Sahih Muslim 2680
Sahih... اللهم أحيني ما كانت الحياة خيرا لي ...
"O Allah, keep me alive as long as life is better for me."
The dua to say instead.
Sahih Muslim 2999
Sahih... عجبا لأمر المؤمن إن أمره كله خير ...
"How wonderful is the affair of the believer: all of it is good for him."
Even hard days carry reward for the believer.
Where the ruling is recorded
- Radd al-Muhtar (Ibn Abidin), Kitab al-Hazr wa al-Ibaha. Wishing for death because of worldly harm is makruh, and there is no harm in it out of fear of trial in religion.
Checked by our team. For a more accurate answer to your own situation, consult a scholar. Quran translation by Sahih International. Hadith Arabic from the standard editions of the six books and the Muwatta, with gradings as recorded there; the English is our own rendering. Spotted a mistake? Tell us.