It is narrated from Sayyiduna Bara’ bin ‘Azib (may Allah be pleased with them both) that the Noble Prophet (peace and blessings be upon him) taught a man these words, that when he goes to his bed, he should say in this manner: “«اللّٰهُمَّ وَجَّهْتُ وَجْهِيَ إِلَيْكَ، وَأَلْجَأْتُ ظَهْرِي إِلَيْكَ، وَفَوَّضْتُ أَمْرِي إِلَيْكَ، وَأَسْلَمْتُ نَفْسِي إِلَيْكَ، رَهْبَةً مِنْكَ، وَرَغْبَةً إِلَيْكَ، وَلَا مَلْجَأَ وَلَا مَنْجَا مِنْكَ إِلَّا إِلَيْكَ، آمَنْتُ بِكِتَابِكَ الَّذِي أَنْزَلْتَ وَنَبِيِّكَ الَّذِي أَرْسَلْتَ»” “O Allah! I have turned my face towards You, and entrusted my back to You, and have handed over my affair to You, and have entrusted my soul to You, fearing You and desiring towards You. There is no refuge and no escape from You except with You. I have believed in Your Book which You have revealed and in Your Messenger whom You have sent.” The Prophet (peace and blessings be upon him) said: If he dies that night, all his sins are forgiven.
Related hadith on this topic