It is narrated from Sayyiduna Ibn Abbas (may Allah be pleased with them both) that a man from Azd Shanu'ah called Dimam lived in Yemen, and he used to treat ailments caused by the jinn. He came to Makkah and heard people saying about Sayyiduna Muhammad (peace and blessings be upon him) that he was a sorcerer, a soothsayer and a madman. So he said (to himself): If I go to this man, perhaps Allah will cure him at my hands. So he met him and said: O Muhammad, Allah, the Mighty and Majestic, grants cure at my hands, and I treat these spirits. He (peace and blessings be upon him) said: "All praise is for Allah; we praise Him and seek His help. Whomever Allah guides, none can lead astray, and whomever He leads astray, none can guide. And I bear witness that there is no true god except Allah, and I bear witness that Muhammad is His servant and Messenger." He said: Repeat this to me. So he (peace and blessings be upon him) repeated it to him three times. He said: I have heard the words of soothsayers, sorcerers and poets, but I have never heard anything like these words, and they have reached the depths of the sea. Stretch out your hand so that I may pledge allegiance to you on Islam. So he (peace and blessings be upon him) stretched out his hand, and he pledged allegiance on Islam, and he also pledged allegiance on behalf of his people.
Hadith Referenceالمعجم الكبير للطبراني / باب الضاد / 8116