Joseph was purchased by Potipher, but God was with Joseph. Joseph was entrusted with the matters of Potipher's house, and Potipher's wife attempts to seduce Joseph, but he refuses because it is wicked. When he refuses, she falsely accuses him and Potipher throws him into prison.
When he is in prison, Pharaoh's butler comes to Joseph and asks him to interpret a dream. Joseph tells the butler that interpretation of dreams come from God, and gives him a very positive interpretation, asking the butler to remember him when he comes into power. When the baker hears this, the baker asks him to interpret a dream, but this is a dream that foretells that baker's death.
These things come to pass, but the baker does not remember Joseph to Pharaoh until Pharaoh has a dream, and then Joseph tells Pharaoh that his dream indicates years of prosperity followed by years of famine and that they should take from their prosperity to prepare for the years of famine.
For this, Pharaoh sets Joseph over his house and all of Egypt. Joseph assimilates into the culture, takes a wife, Asenath, and has the children Manasseh, for forgetting his hardships in his father's house, and Ephraim, for the fruitfulness that God has given Joseph.