7 And it came to pass after these things that his master’s wife cast longing eyes on Joseph, and she said, “Lie with me.”
8 But he refused and said to his master’s wife, “Look, my master does not know what is with me in the house, and he has committed all that he has to my hand.
9 There is no one greater in this house than I, nor has he kept back anything from me but you, because you are his wife. How then can I do this great wickedness, and sin against God?”
10 So it was, as she spoke to Joseph day by day, that he did not heed her, to lie with her or to be with her.
11 But it happened about this time, when Joseph went into the house to do his work, and none of the men of the house was inside,
12 that she caught him by his garment, saying, “Lie with me.” But he left his garment in her hand, and fled and ran outside.
13 And so it was, when she saw that he had left his garment in her hand and fled outside,
14 that she called to the men of her house and spoke to them, saying, “See, he has brought in to us a Hebrew to mock us. He came in to me to lie with me, and I cried out with a loud voice.
15 And it happened, when he heard that I lifted my voice and cried out, that he left his garment with me, and fled and went outside.”
16 So she kept his garment with her until his master came home.
17 Then she spoke to him with words like these, saying, “The Hebrew servant whom you brought to us came in to me to mock me;
18 so it happened, as I lifted my voice and cried out, that he left his garment with me and fled outside.”
19 So it was, when his master heard the words which his wife spoke to him, saying, “Your servant did to me after this manner,” that his anger was aroused.
20 Then Joseph’s master took him and put him into the prison, a place where the king’s prisoners were confined. And he was there in the prison.
21 But the Lord was with Joseph and showed him mercy, and He gave him favor in the sight of the keeper of the prison.
22 And the keeper of the prison committed to Joseph’s hand all the prisoners who were in the prison; whatever they did there, it was his doing.
23 The keeper of the prison did not look into anything that was under Joseph’s authority, because the Lord was with him; and whatever he did, the Lord made it prosper.
Joseph’s imprisonment and subsequent events are mentioned in Psalm 105:17-22: He sent a man before them—Joseph—who was sold as a slave. They hurt his feet with fetters, he was laid in irons. until the time that his word came to pass, the word of the Lord tested him. The king sent and released him, the ruler of the people let him go free. He made him lord of his house, and ruler of all his possessions, to bind his princes at his pleasure, and teach his elders wisdom.
In rejecting [Potiphar’s wife’s] invitation, Joseph tried not to offend her. [He didn’t say that] she was unattractive or undesirable, nor that he was condemning her as immoral for making such a proposal, but that there were greater considerations which must take precedence. His master, and her husband, trusted him fully; it would be a terrible betrayal of his trust for Joseph to take the one thing he had kept from him, his own wife. Even more importantly, such an action would be a great sin against God Himself! Even though neither her husband nor the other servants should ever find out, God would know. … Potiphar’s wife, however, was nor persuaded by Joseph’s good and proper reasoning, but continued day after day trying to attract him to her bed. Joseph not only continued to refuse, but began to avoid her altogether, trying not even “to be with her.” — Morris, pages 561-562