Prison was Joseph's third test. During this period Allah blessed him with an extraordinary gift; the ability to interpret dreams. At about the same time two other men landed in the prison. One was the cupbearer of the king; the other was the king's cook. The two men sensed that Joseph was not a common criminal, for an aura of piety glowed on his face. Both men had vivid dreams, and they were anxious to have them explained. The king's cook dreamed that he stood in a place with bread on his head, and two birds were eating the bread. The cupbearer dreamed that he was serving the king wine. The two went to Joseph and told him their dreams, asking him to give them their meaning.
First, Joseph called them to Allah. Then he said that the cook would be crucified until he died and that the cupbearer would return to the service of the king. Joseph told the cupbearer to remember him to the king and to say that there was a wronged soul called Joseph in prison. What Joseph predicted did happen; the cook was crucified and the cupbearer returned to the palace.
After the cupbearer returned to service, Satan made him forget to mention Joseph's name to the king. Therefore, Joseph remained in prison for a few years, but he made patience his own, praying to Allah.
Almighty Allah narrated: And there entered with him two young men in the prison. One of them said: "Verily, I saw myself (in a dream) pressing wine." The other said: "Verily, I saw myself (in a dream) carrying bread on my head and birds were eating thereof." They said: Inform us of the interpretation of this. Verily, we think you are one of those Muhsineen (doers of good)."
He said: "No food will come to you (in wakefulness or in dream) as your provision but I will inform (in wakefulness) its interpretation before it (the food) comes. This is of that which my Lord has taught me. Verily, I have abandoned the religion of a people that believe not in Allah and are disbeliveers in the Hereafter. And I have followed the religion of my fathers, - Abraham, Isaac, and Jacob and never could we attribute any partners whatsoever to Allah. This is from the Grace of Allah to us and to mankind, but most men think not (i.e. they neither believe in Allah nor worship Him).
"O two companions of the prison! Are many different lords (gods) better or Allah, the One, the Irresistible? You do not worship besides Him but only names which you have named (forged), you and your fathers, for which Allah has sent down no authority. The command (or the judgment) is for none but Allah. He has commanded (His Monotheism), that is the true, straight religion, but most men know not.
"O two companions of the prison! As for one of you, he (as a servant) will pour out wine for his lord (King or master) to drink; and as for the other, he will be crucified and birds will eat from his head. Thus is the case judged concerning which you both did inquire."
And he said to the one whom he knew to be saved: "Mention me to your lord (your King, so to get me out of the prison)." But Satan made him forget to mention it to his lord (or Satan made Joseph to forget the remembrance of his Lord (Allah) as to ask for His Help, instead of others). So Joseph stayed in prison a few more years. (Ch 12:36-42).
The scene in the prison closes; a new scene opens in the bedchamber of the king. The king is asleep. He sees himself on the banks of the Nile river. The water is receding before him, becoming mere mud. The fish begin to skip and jump in the mud. Seven fat cows come out of the river followed by seven lean cows. The seven lean ones devour the seven fat ones. The king is terrified. The seven ears of green grain grow on the riverbanks and disappear in the mud. One the same spot grow seven dray ears of grain.
The king awoke frightened, shocked, and depressed, not knowing what all this meant. He sent for the sorcerers, priests and ministers, and told them his dream.
The sorcerers said: "This is a mixed up dream. How can any of that be? It is a nightmare."
The priests said: "Perhaps his majesty had a heavy supper."
The chief minister said: "Could it be that his majesty was exposed and did not draw the blanket up at night?"
The king's jester said, jokingly: "His majesty is beginning to grow old, and so his dreams are confused."
They reached an unanimous conclusion that it was only a nightmare.
The news reached the cupbearer. He recollected the dream he had in prison and compared it to the king's dream, and, therefore Joseph came to mind. He ran to the king to tell him about Joseph, who was the only one capable to interpreting the dream. The cupbearer said : "He had asked me to remember him to you, but I forgot." The king sent the cupbearer to ask Joseph about the dream.
Joseph interpreted it to him: "There will be seven years of abundance. If the land is properly cultivated, there will be an excess of good harvest, more than the people will need. This should be stored. Thereafter, seven years of famine will follow, during which time the excess grain could be used."
He also advised that during the famine they should save some grain to be used for seed for the next harvest. Joseph then added; "After seven years of drought, there will be a year during which water will be plentiful. If the water is properly used, grapevines and olive trees will grow in abundance, providing plenty of grapes and olive oil."
The cupbearer hurried back with the good news. The king was fascinated by Joseph's interpretation. Almighty Allah narrated this incident thus: And the king of Egypt said: "Verily, I saw in a dream seven fat cows, whom seven lean cows were devouring, and seven green ears of corn and seven others dry. O notables! Explain to me my dream if it be that you can interpret dreams."
They said: "Mixed up false dreams and we are not skilled in the interpretation of dreams."
Then the man who was released (one of the two who were in prison), now at length remembered and said: "I will tell you its interpretation, so send me forth."
(He said): "O Joseph, the man of truth! Explain to us (the dream) of seven fat cows whom seven lean ones were devouring, and of seven green ears of corn and seven others dry, that I may return to the people, and that they may know." Joseph said: "For seven consecutive years, you shall sow as usual and that the harvest which you reap you shall leave in ears, all --except a little of it which you may eat. Then will come after that seven hard years, which will devour what you have laid by in advance for them, all except a little of that which you have guarded (stored). Then thereafter will come a year in which people will have abundant rain and in which they will press wine and oil." (Ch 12:43-49)
The king was greatly astonished. Who could this person be? He commanded that Joseph be set free from prison and presented to him at once. The king's envoy went to fetch him immediately, but Joseph refused to leave the prison unless his innocence was proven. Perhaps they accused him of cutting the ladies hands, or trying to rape them. Perhaps any other false accusation was made.
We do not know exactly what was said to the people to justify Joseph's sentence to prison. The envoy returned to the king. The king asked him: "Where is Joseph? Did I not command you to fetch him?"
The envoy replied: "He refused to leave until his innocence is established regarding the ladies who cut their hands."
The king ordered: "Bring the wives of the ministers and the wife of the chief minister at once." The king felt that Joseph had been harmed unfairly but he did not know exactly how. The wife of the chief minister came with the other ministers' wives. The king asked: "What is the story of Joseph? What do you know about him? Is it true that…?"
One of the ladies interrupted the king exclaiming: "Allah forbid!"
A second said: "We know of no evil he has done."
A third said: "He enjoys the innocence of angels."