He heard him narrate from the Messenger of Allah ﷺ that he stood among them and mentioned to them that jihad in the path of Allah and belief in Allah are the best of deeds.A man stood up and asked, "Messenger of Allah, what do you think, if I am killed in the path of Allah, will my sins be wiped away?"The Messenger of Allah ﷺ replied, "Yes, if you are killed in the path of Allah while being patient, seeking reward, advancing and not retreating."Then the Messenger of Allah ﷺ asked, "What did you say?"The man repeated, "What do you think, if I am killed in the path of Allah, will my sins be wiped away?"The Messenger of Allah ﷺ answered, "Yes, provided you are patient, seeking reward, advancing and not retreating, except for debt. Jibreel told me that."
حدثنا قتيبة حدثنا الليث عن سعيد بن أبي سعيد المقبري
أنه سمعه يحدث عن رسول الله ﷺ أنه قام فيهم فذكر لهم أن الجهاد في سبيل الله والإيمان بالله أفضل الأعمال فقام رجل فقال يا رسول الله أرأيت إن قتلت في سبيل الله يكفر عني خطاياي فقال رسول الله ﷺ نعم إن قتلت في سبيل الله وأنت صابر محتسب مقبل غير مدبر ثم قال رسول الله ﷺ كيف قلت قال أرأيت إن قتلت في سبيل الله أيكفر عني خطاياي فقال رسول الله ﷺ نعم وأنت صابر محتسب مقبل غير مدبر إلا الدين فإن جبريل قال لي ذلك
Also narrated by Muslim, Al-Imarah, chapter "Whoever is killed in the path of Allah, his sins are forgiven except debt," Hadith 1885, from Qutayba, with the same wording.On this topic, there are also narrations from Anas [previously mentioned: 1640], Muhammad bin Jahsh [Nasai, Hadith 4688], and Abu Hurairah [Nasai, Hadith 3157].