Anas ibn Malik (رضي الله عنه) reported Allah’s Messenger (صلى الله عليه و سلم) as saying.
None of you should make a request for death because of the trouble in which he is involved, but if there is no other help to it, then say:
O Allah, keep me alive as long as there is goodness in life for me and bring death to me when there is goodness in death for me.
Supplication in Arabic:
اللَّهُمَّ أَحْيِنِي مَا كَانَتِ الْحَيَاةُ خَيْرًا لِي وَتَوَفَّنِي إِذَا كَانَتِ الْوَفَاةُ خَيْرًا لِي
Allaahumma ahyinee maa kaanatil hayaatu khayran lee, wa tawaffanee ithaa kaanatil wafaatu khayran lee.
[Bukhari and Muslim]