Anas bin Malik reported,

The Prophet ﷺ said, "None of you should wish for death because of some harm that has befallen him. If he must do so, 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.'"

Bukhari 5671

Sahih

حدثنا آدم حدثنا شعبة حدثنا ثابت البناني

عن أنس بن مالك رضي الله عنه قال

النبي ﷺ لا يتمنين أحدكم الموت من ضر أصابه فإن كان لا بد فاعلا فليقل اللهم أحيني ما كانت الحياة خيرا لي وتوفني إذا كانت الوفاة خيرا لي

البخاري 5671صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Bukhari
Book
Sick
Chapter
Wishing for death by the sick person
Numbering
Darussalam 5671
Bukhari 5671