Śrīmad-Bhāgavatam · Text 6.10.33
Who is speaking and story frame
द्वौ सम्मताविह मृत्यू दुरापौ
यद् ब्रह्मसन्धारणया जितासु: ।
कलेवरं योगरतो विजह्याद्
यदग्रणीर्वीरशयेऽनिवृत्त: ॥ ३३ ॥
dvau sammatāv iha mṛtyū durāpau
yad brahma-sandhāraṇayā jitāsuḥ
kalevaraṁ yoga-rato vijahyād
yad agraṇīr vīra-śaye ’nivṛttaḥ
There are two ways to meet a glorious death, and both are very rare. One is to die after performing mystic yoga, especially bhakti-yoga, by which one can control the mind and living force and die absorbed in thought of the Supreme Personality of Godhead. The second is to die on the battlefield, leading the army and never showing one’s back. These two kinds of death are recommended in the śāstra as glorious.
Read Śrīla Prabhupāda's purport on Vedabase.io