Experience. Time, patient & accepting that no one is immortal always more difficult to deal with a young patients death than an older.
Takes time. I deal with loss frequently in my field. It never gets easy, but you can develop the skills to cope with the losses. First, it is okay to feel sad and even to cry in front of the patient's family. Of course , a modicum of control is necessary, as you are a professional. Knowing you did your best to care for the person and then enjoying other healthy escapes will help you cope more effectively.