After a total of twelve years in prison, two of which were added because Joseph put his trust in the Chamberlain of the Cupbearers rather than in Hashem, Joseph was released from prison.
Pharaoh had a dream, in which he saw seven fat cows emerge from the river Nile. After a while, seven lean cows emerged from the river and consumed the fat ones.
Pharaoh then had a second dream, in which seven fat stalks of grain emerged. Again, after a while seven lean stalks emerged and consumed the seven fat ones.
Pharaoh tried finding an interpreter for his dreams but neither any of the wise men nor any of the necromancers at his court were able to interpret his dreams.
The Chamberlain of the Cupbearers remembered Joseph, who had interpreted his dream in the last Parashas. The Chamberlain informed Pharaoh about Joseph, and Joseph was led to Pharaoh.
After hearing Joseph's interpretation of Pharaoh's dreams, Pharaoh was more than impressed of Joseph's skills. Pharaoh decided to make Joseph viceroy over Egypt – Joseph became the de facto ruler of Egypt, Pharaoh just kept his higher rank.
Hashem helped Joseph understand Pharaoh's dreams: Seven years of plentiful grain and food would be followed by seven years of famine. The two dreams emphasized the immediacy of G'd plan.
Back in Eretz Israel, then still known as Canaan, Joseph's father Jacob and his sons are also affected by the famine, and Jacob decided to send all his sons bar Benjamin, his only son by his deceased wife Rachel, to Egypt to ask for food.
In Egypt, Joseph recognized his brothers but they did not recognize him. He calls them "spies" that came to spy out the land, alluding to the episode of the spies during Moshe's time, before the Israelites tried to enter the land for the first time.
Joseph kept Simeon imprisoned and told his brothers to return with their younger brother Benjamin to prove that they are not spies.
Joseph arranged for the brother's money to be returned in their sacks.
The brothers returned to Jacob. The famine got very bad again. They went back to Egypt with Benjamin, and as their sacks were being filled with new provisions, Joseph arranged for his goblet to be hidden in Benjamin's sack. On their way back to Canaan, the brothers were stopped by one of Joseph's servants, his son Menashe, who returned the brothers to Joseph. Joseph wanted to make Benjamin his servant for the crime of apparently having stolen his divination cup.
In my local community, the Rabbi shared the following teaching regarding this Parashas:
In Hebrew there are several words that mean "end", there is "Mikeitz" and there is also "Sof".
The two words encapsulate different concepts, "Mikeitz" refers to what is called a "left end", "Sof" refers to a "right end".
A "left end" is a strict ruling that something come to an end.
An example for such a "left end" ruling would be Shabbat candles: When they have been lit, Shabbat is here, and a Jewish person is limited in the kind of activities they can do. One becomes passive in one's actions.
Joseph's brothers represent this aspect of Shabbat candles, they are considered passive.
As they would soon realize they were just acting out G'd's plan to save Jacob and his family when they sold Joseph to Egypt. Also, they would soon bow to their brother and be rescued by him.
The "right end" is different: Lighting Chanukka candles is considered an active action, it is something that is done to bring light in the world. Joseph's life represents this, his life was filled in action and it was active. After having been sold by brothers, he worked for Potiphar, when he was in prison, he also worked there and upon his release he continued working as viceroy of Egypt.
The word "Mikeitz" is used also at other times in the Torah: The end of the story of Cain and Abel is described as a "Mikeitz", as it ends with the destruction of a brother.
In the story of Noach, we find another instance of a "Mikeitz" when Noach and his family are the last survivors after the flood.
In Parashas Mikeitz, the word "Mikeitz" is used to refer to the end of Joseph's imprisonment after the two additional years he had to spend in prison for having put his trust in the Chamberlain of the Cupbearers instead of G'd.
When Joseph called his brothers spies, this is an allusion to an event of the future, to the episode of the spies who refused to enter the land of Israel at the time of Moshe.
By referring to his brothers as spies, Joseph tried to prevent the sin from becoming true, which is a similar to when Abraham fought in the War of the Five and Four Kings and felt dread when he came near the area of the Eigel.
Just as the Eigel, Abraham's descendendants' sin, represents an iniquity in Abraham as well, so does the episode of the spies represent an iniquity in Joseph's brothers.