Bara bin Azib reported,

We went out with the Messenger of Allah ﷺ to attend the funeral of a man from the Ansar. When we reached the grave, the niche had not yet been dug. The Messenger of Allah ﷺ sat down, and we sat around him so still it was as though birds were perched on our heads. In his hand was a stick with which he was poking the ground. Then he raised his head and said, "Seek refuge in Allah from the punishment of the grave," repeating it two or three times.He mentioned the hadith in its full length, and it will appear in the chapter on the affirmation of the punishment of the grave.

Azami 3814

Sahih

عن البراء بن عازب قال

خرجنا مع رسول الله ﷺ في جنازة رجل من الأنصار، فانتهينا إلى القبر ولما يلحد، فجلس رسول الله ﷺ وجلسنا حوله كأنما على رؤوسنا الطير، وفي يده عود ينكت به في الأرض، فرفع رأسه فقال: استعيذوا بالله من عذاب القبر مرتين أو ثلاثا، وذكر الحديث بطوله وسيأتي في باب إثبات عذاب القبر.

الأعظمي 3814صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Funerals
Chapter
Graves
Section
Sitting at the grave during burial for reminding and admonishing
Numbering
Jami al-Kamil 3814 (2nd edition)
Azami 3814