Bulugh al-Maram, Book 1, Hadith 97 (In-Book)

Narrated Mu’awiyah (rad): Allah’s Messenger (saW) said: “The eye (when awake) is the string of the anus (to stop air escaping), and if the two eyes sleep the string is untied”. [Reported by Ahmad and At-Tabarani who added, “Whoever sleeps should perform ablution]”

وَعَنْ مُعَاوِيَةَ ‏- رضى الله عنه ‏- قَالَ: قَالَ رَسُولُ اَللَّهِ ‏- صلى الله عليه وسلم ‏-{ الْعَيْنُ وِكَاءُ السَّهِ, فَإِذَا نَامَتْ اَلْعَيْنَانِ اِسْتَطْلَقَ اَلْوِكَاءُ } رَوَاهُ أَحْمَدُ, وَالطَّبَرَانِيُّ وَزَادَ { وَمَنْ نَامَ فَلْيَتَوَضَّأْ }

sunnah.com

also referenced under: Book 1, Hadith 86 (English)