Joseph tells his brothers about a dream he had in which his brothers’ sheaves of wheat bowed to his sheaf. This makes them hate him more than they already do. Then he tells his brothers and father about a dream he had in which the sun, moon, and eleven stars bowed to him. This makes his brothers jealous and is of concern to his father. His brothers plot to kill him, then after they decide not to do that they throw him into a pit and he is sold to some Ishmaelite merchants on their way to Egypt, who transport him on the back of a camel along with their other goods. Later, Joseph’s brother Judah engages the services of a veiled prostitute sitting by the entrance to Enaim. He doesn’t know that the prostitute is his widowed daughter-in-law Tamar*. Meanwhile in Egypt, Joseph has been purchased by Potiphar, courtier of the Pharaoh. He has risen to a high position in the household due to his excellent service. While Potiphar is away, Potiphar’s wife tries to seduce Joseph. Joseph flees as Potiphar’s wife grabs at his garment.
*Context: Upon the deaths of her previous husbands Er and Onan (Judah's sons), Judah had not allowed Tamar to marry his son Shelah, which left Tamar with very limited options in life. Tamar knew Judah would be at Enaim and went there with her veil on, in order to initiate the carnal transaction, in protest of the impossible circumstance she found herself in. Later, Judah will learn about Tamar's engagement in prostitution (and subsequent pregnancy) and order her to be burned alive. As she's being taken out to receive this lethal punishment, she will reveal that she was the prostitute Judah went to bed with at Enaim, and that the children she is carrying are Judah's. On learning of this, he will acknowledge that he was more in the wrong than she was since he did not allow her to remarry. (You'd think that insight could already have occurred to him when all he knew was that Tamar had worked as a prostitute, but it seems that the ideas is, he understands that her act was intended to send him a message, she's not really a prostitute but a family member acting out in an unjust situation. Or maybe Judah realizes that, while the hypocrisy of punishing a relative for prostitution when you are a client of prostitutes is one thing, it's even more extreme when you were the client in the transaction for which you have now pronounced punishment.) We are not told that the execution order was rescinded but apparently it was since Tamar goes on to give birth to twins conceived in her union with Judah.