Let us take a look at the always relevant questions about free will in light of Yosef’s choice to overcome the temptation of Potiphar’s wife.
The Sefat Emet explains the fact that Hashem did not allow Yaakov to know that Yosef had been sold into slavery in Egypt as follows. On one hand, in order for Bnei Yisrael to be redeemed eventually from Egypt, Yosef had to undergo his experience as a slave there. On the other hand, Yaakov was aware of the moral decadence that was prevalent in Egypt and that certainly one who was in the lowly position of a slave there could not naturally maintain his spiritual level. Yaakov would have been overcome with grief to know that this was Yosef’s lot. The Sefat Emet explains that there are two types of moral challenges that a person faces. One is a test that he has the ability to pass by means of properly using his free will. The other is a temptation so great that he cannot naturally overcome it. However, Hashem can intervene and enable one to overcome even such a temptation. Yosef, who had gone from a favored son to a slave, was elevated to prominence in his master’s house, and was placed in an irresistible predicament, was in the latter situation.
Yosef was the recipient of such Divine intervention in his struggle to turn down Potiphar’s wife and maintain his moral standing in the depths of Egypt. He merited this help because he was not responsible for the terrible predicament he was in. He did not deserve to be sold into slavery and was a pawn in the Divine Plan in this regard. Therefore, he was given the opportunity to succeed where it should not have been possible.
However, this does not mean that Yosef did not pass the test by virtue of his moral greatness. As the Sefat Emet says, only when a person has a sincere desire to take away the choice that the moral struggle presents does he merit Divine Intervention. Yosef, with all the reasons for bitterness in regard to his predicament, realized that the free will which he possessed was given to him by Hashem. Realizing this, he came to a resolute decision that it would be wrong to use his opportunity to sin as an excuse to violate Hashem’s moral laws and to sin with Potiphar’s wife. This conviction is described by the Torah in a single word: "Vayema’en (he refused)." As a result of this decision to try not to exercise his free will, Hashem intervened and gave him the Divine Assistance which enabled him to extricate himself from the predicament.
Yosef’s decision to forgo his free will is that which turned him into a free man, as matters progressed. This is also what made the exodus from Egypt possible and enabled Am Yisrael to be a free nation in its Land until this day.