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 the 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.