It is narrated from Sayyiduna Abdullah bin Mas'ud (may Allah be pleased with him) that we were returning with the Messenger of Allah (peace and blessings be upon him) from Hudaybiyah, and we camped at night in the wilderness. He (peace and blessings be upon him) said: "Who will wake us for our prayer?" Shu'bah says that he (peace and blessings be upon him) said: "Who will keep guard over us?" Sayyiduna Bilal (may Allah be pleased with him) said: "I will." Al-Mas'udi says in his narration that he (peace and blessings be upon him) said: "You will fall asleep." Then he said: "Who will wake us for our prayer?" Ibn Mas'ud (may Allah be pleased with him) says: I said: "I will, O Messenger of Allah (peace and blessings be upon him)!" The Messenger of Allah (peace and blessings be upon him) said: "You will fall asleep." So I kept guard over them, until, when morning was near, what the Messenger of Allah (peace and blessings be upon him) had said happened to me (that you will fall asleep), and I fell asleep. We woke up because of the sunshine. The Messenger of Allah (peace and blessings be upon him) got up and did as he usually did, then said: "Had Allah willed that you should not sleep, you would never have slept; but Allah willed that the ruling become clear for those who come after you. So if any of you sleeps or forgets, do like this."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 3182