The Prophet ﷺ said to a man, "When you lie down to sleep or retire to your bed, say, 'O Allah, I submit my face to You, I entrust my back to You, and I commit my affair to You, in hope of You and in fear of You. There is no refuge or escape from You except to You. I believe in Your Book which You revealed and in Your Prophet whom You sent.' If you die that night, you will die upon the natural disposition of faith, and if you wake in the morning, you will have attained much good."
حدثنا علي بن محمد حدثنا وكيع حدثنا سفيان عن أبي إسحق
أن النبي ﷺ قال لرجل إذا أخذت مضجعك أو أويت إلى فراشك فقل اللهم أسلمت وجهي إليك وألجأت ظهري إليك وفوضت أمري إليك رغبة ورهبة إليك لا ملجأ ولا منجأ منك إلا إليك آمنت بكتابك الذي أنزلت ونبيك الذي أرسلت فإن مت من ليلتك مت على الفطرة وإن أصبحت أصبحت وقد أصبت خيرا كثيرا
[Sahih]. Ahmad narrated it, 4/299, from Waki, from him. It has other routes narrated by Bukhari, no. 6313, and Muslim, no. 271/58, and others, from Abu Ishaq, from him. It also has other routes from Bara.