Genesis 39 is framed by a repeated phrase: Yahweh was with Joseph (verses 2, 3, 21, 23). It appears at the beginning when Joseph prospers in Potiphar's house, and again at the end when he is in prison. God's presence is the constant in both success and suffering. The chapter also shows God's blessing spilling over onto an Egyptian household for Joseph's sake, a small fulfillment of the promise that the nations would be blessed through Abraham's family.
Potiphar's wife repeatedly tempts Joseph. His refusal is a model of moral reasoning: he names his responsibility to his master who trusts him, and then the deepest reason: How then can I do this great wickedness, and sin against God? Joseph knows that all sin is first against God (compare Psalm 51:4). When words are not enough, he flees, leaving his garment behind. Joseph loses a coat for the second time, and once again a garment is used to deceive.
Falsely accused, Joseph is thrown into prison. Yet the Lord showed kindness to him (steadfast love, hesed), and Joseph rises to responsibility again. Joseph's story contrasts with Judah's in chapter 38: Judah gave in to temptation in the promised land, while Joseph resisted in a foreign land. Christians have read this as a picture of Jesus, who was tempted yet without sin (Hebrews 4:15), and who was falsely accused.