Al-Hasan bin Jabir al-Qurashi (may Allah have mercy on him) narrates from Sayyiduna Mu'adh bin Jabal (may Allah be pleased with him) that he heard a rustling sound, so he seized it and said: Who are you? It said: I am a devil. He said: Come to the Messenger of Allah (peace and blessings be upon him). It said: Let me go, for I will not come back. So he let it go. When he came to the Prophet (peace and blessings be upon him) in the morning, he (peace and blessings be upon him) said: "O Mu'adh! What did your captive do?" He said: I released him. Then on the second night he sensed it again and seized it; it pleaded with him again and swore that it would not return, so he let it go. Then on the third night he sensed it and seized it, and it pleaded with him again and swore that it would not return, but this time he refused to release it. It said: Let me go so that I may teach you a verse; when you recite it, we will not come near that place. And it taught him Ayat al-Kursi, so he let it go. In the morning he came to the Messenger of Allah (peace and blessings be upon him) and told him what had happened, and he (peace and blessings be upon him) said: "He spoke the truth, even though he is a great liar."
Hadith Referenceالمعجم الكبير للطبراني / باب الميم / 17333