When the Prophet ﷺ intended to sleep, he would place his hand beneath his head and say, "O Allah, protect me from Your punishment on the Day You gather," or "resurrect Your servants."
حدثنا ابن أبي عمر حدثنا سفيان عن عبد الملك بن عمير عن ربعي بن حراش
أن النبي ﷺ كان إذا أراد أن ينام وضع يده تحت رأسه ثم قال اللهم قني عذابك يوم تجمع أو تبعث عبادك
Sahih. Ahmad reported it: 5/382, and Humaydi, no. 445, from Sufyan bin Uyayna with the same wording, and he explicitly stated that he heard it directly. The hadith has corroborating narrations in Abu Dawud, no. 5045, and Ibn Majah, no. 3877, and others.