And they followed [instead] what the devils had recited during the reign of Solomon. It was not Solomon who disbelieved, but the devils disbelieved, teaching people magic and that which was revealed to the two angels at Babylon, Hārūt and Mārūt. But they [i.e., the two angels] do not teach anyone unless they say, "We are a trial, so do not disbelieve [by practicing magic]."1 And [yet] they learn from them that by which they cause separation between a man and his wife. But they do not harm anyone through it except by permission of Allāh. And they [i.e., people] learn what harms them and does not benefit them. But they [i.e., the Children of Israel] certainly knew that whoever purchased it [i.e., magic] would not have in the Hereafter any share. And wretched is that for which they sold themselves, if they only knew.
Translation: Saheeh International (English)
1 They warn people against the misuse of what they have learned.
When they left the path of Allah, they followed instead what the satans said: lying about the kingdom of the Prophet Solomon (peace be upon him) by claiming that it was established through black magic. Solomon did not disbelieve by practicing black magic, as the Jews claimed; but the satans were disbelievers when they taught people the black magic revealed to the two angels, Hārūt and Mārūt, in the city of Babel in Iraq. These two angels would only teach black magic to someone after explaining that they were simply a trial and a test for people, warning them not to be ungrateful to Allah by learning it. Those who learned black magic from them but did not listen to their advice would, through it, separate a man and his wife by sowing hatred between them. These sorcerers are not able to harm anyone except with Allah’s permission and by His will. They learn what harms them and does not benefit them. This group of Jews knew that whoever exchanges the scripture of Allah for black magic will have no portion in the Afterlife. What an evil thing they sold their souls for when they exchanged the revelation and sacred law of Allah for black magic! If they had known what would benefit them, they would not have done something so disgraceful and clearly misguided.