COMMENTARY on 12:24
Mustafa Khattab:

Translation:
She advanced towards him, and he would have done likewise, had he not seen a sign from his Lord.7 This is how We kept evil and indecency away from him, for he was truly one of Our chosen servants.
Commentary:
7   Joseph (ﷺ) received warning against fornication either through divine inspiration or a vision of his father.

 

A. Yusuf Ali:

Translation:
And (with passion) did she desire him, and he would have desired her, but that he saw the evidence 1668 of his Lord: thus (did We order) that We 1669 might turn away from him (all) evil and shameful deeds: for he was one of Our servants, sincere and purified.
Commentary:

1668  She was blinded with passion, and his plea had no effect on her. He was human after all, and her passionate love and her beauty placed a great temptation in his path. But he had a sure refuge-his faith in Allah. His spiritual eyes saw something that her eyes, blinded by passion, did not see. She thought no one saw when the doors were closed. He knew that Allah was there and everywhere. That made him strong, and proof against temptation.

1669  The credit of our being saved from sin is due, not to our weak earthly nature, but to Allah. We can only try like Joseph, to be true and sincere: Allah will purify us and save us from all that is wrong. Tempted but true, we rise above ourselves.

 

Muhammad Asad:

Translation:
And, indeed, she desired him, and he desired her; [and he would have succumbed] had he not seen [in this temptation] an evidence of his Sustainer's truth: 23 thus [We willed it to be] in order that We might avert from him all evil and all deeds of abomination -for, behold, he was truly one of Our servants. 24
Commentary:
23  The interpolated phrase "and he would have succumbed", is, according to Zamakhshari, implied in the above sentence. In his commentary on this verse, he further points out that the moral significance of "virtue" consists in one's inner victory over a wrongful desire, and not in the absence of such a desire. Cf. the well-known saying of the Prophet, recorded, on the authority of Abu Hurayrah, by Bukhari and Muslim: "God, exalted be He, says: 'If a servant of Mine [merely] desires to do a good deed, I shall count this [desire] as a good deed; and if he does it, I shall count it tenfold. And if he desires to commit a bad deed, but does not commit it, I shall count this as a good deed, seeing that he refrained from it only for My sake..."' -i.e., in consequence of a moral consideration (which, in the present instance, is described as "an evidence of God's truth").
24  Lit., "he was among Our sincere servants".