Prophet Yūsuf: Part 1 — The Well, the House and the Prison
Section 18 of 31 · Lives of the Prophets
The Proof of His Lord
وَلَقَدْ هَمَّتْ بِهِۦ ۖ وَهَمَّ بِهَا لَوْلَآ أَن رَّءَا بُرْهَـٰنَ رَبِّهِۦ ۚ كَذَٰلِكَ لِنَصْرِفَ عَنْهُ ٱلسُّوٓءَ وَٱلْفَحْشَآءَ ۚ إِنَّهُۥ مِنْ عِبَادِنَا ٱلْمُخْلَصِينَ
“She certainly desired him, and he might have desired her, had he not seen the proof from his Lord. Thus We did, to turn evil and lewdness away from him. Surely, he was one of Our chosen servants.” (12:24)
And she certainly desired him, and he would have inclined to her desire, had he not seen the evidence of his Lord. She desired him — wa laqad hammat bih — and he too had that impulse — wa hamma bihā. Her desire was in her heart, and she was acting on it. The idea passed through his heart, but he did not act on it.
We know from the hadith that the Messenger of Allah (peace be upon him) said: if you intend to do evil and then you do it, Allah (swt) writes it down against you as one evil deed; and if you think about doing evil but then you do not do it, Allah (swt) writes it down as a good deed. So the thought itself passed through the heart of Yūsuf (peace be upon him), but he did not act on it. He shut that door and sought refuge in Allah (swt); he drove it out of his heart, and he refused.
Thus it was, that We might turn away from him evil and indecency; he was one of Our chosen, sincere servants. Allah (swt) says that Yūsuf had ikhlāṣ, and that he was chosen.