Anas ibn Malik reported: The Prophet, peace and blessings be upon him, said, “None of you should wish for death due to a calamity that has afflicted him. Yet if he must do something, let him say: O Allah, keep me alive so long as life is good for me, and cause me to die if death is better for me.”
Source: Ṣaḥīḥ al-Bukhārī 5671, Ṣaḥīḥ Muslim 2680
Grade: Muttafaqun Alayhi (authenticity agreed upon) according to Al-Bukhari and Muslim
عَنْ أَنَسِ بْنِ مَالِكٍ رَضِيَ اللَّهُ عَنْهُ قَالَ النَّبِيُّ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ لَا يَتَمَنَّيَنَّ أَحَدُكُمْ الْمَوْتَ مِنْ ضُرٍّ أَصَابَهُ فَإِنْ كَانَ لَا بُدَّ فَاعِلًا فَلْيَقُلْ اللَّهُمَّ أَحْيِنِي مَا كَانَتْ الْحَيَاةُ خَيْرًا لِي وَتَوَفَّنِي إِذَا كَانَتْ الْوَفَاةُ خَيْرًا لِي
5671 صحيح البخاري كتاب الأشربة باب تمني المريض الموت
2680 صحيح مسلم كتاب الذكر والدعاء والتوبة والاستغفار باب كراهة تمني الموت لضر نزل به