The Talmud teaches that even a person who has recited the Shema in the synagogue should recite it again on his bed (Berachot 4b). The custom is called Kriat Shema al HaMitah, the reading of the Shema on the bed, and it is the last thing a person says before sleep.
What is said
The core is the first paragraph of the Shema, preceded by the blessing HaMapil, “who casts the bonds of sleep upon my eyes.” The Talmud says a person who is learned in Torah may say only the first paragraph, with one verse, and many siddurim add more (Berachot 5a). Psalm 91, which the Sages call the song against harmful spirits (Shevuot 15b), is also commonly included, along with the verse “Into Your hand I entrust my spirit” (Tehillim 31:6). The siddurim also carry a short prayer for protection that names the angels Michael, Gavriel, Uriel and Refael.

Sleep as a small death
The Sages call sleep one sixtieth of death (Berachot 57b). This is why the verse about entrusting the spirit sits at the center of the bedtime prayers, and why the first words on waking, Modeh Ani, thank Hashem for returning the soul. The prayers at night and the prayers in the morning belong to the same pair. The Kabbalists add that the soul rises during sleep and is judged and renewed (see the five levels of the soul), and the protection recited at night is connected to the forces described in the spiritual worlds and protection from evil.
Forgiving others first
Siddurim following the Arizal open the bedtime service with a short declaration in which a person forgives anyone who wronged him that day, whether in money, in body or in honor. It begins with the words Hareni mochel, “I hereby forgive.” The idea is to enter sleep with no claim against anyone. The same night-time spirit lies behind the midnight lament covered in Tikkun Chatzot, and the blessing for the moon in Kiddush Levanah belongs to the same night.