This is the most detailed and fascinating story in the Qur'an, involving both human weaknesses such as jealousy, hatred, pride, passion, deception, intrigue, cruelty, terror as well as noble qualities such as patience, loyalty, bravery, nobility, and compassion.
It is related that among the reasons for its revelation is that the Jews asked the Prophet Muhammad to tell them about Joseph , who was one of their old prophets. His story had been distorted in parts and marred in others with interpolations and exclusions. Therefore it was revealed in the Book of Allah (Qur'an), complete in its minute and careful details.
Allah the Almighty declared: We relate unto you (Muhammad) the best of stories through Our Revelations unto you, of this Qur'an. And before this (i.e. before the coming of Divine Inspiration to you), you were among those who knew nothing about it (the Qur'an). Surah 12: 3
Almighty Allah also decreed: Thus We relate to you (0 Muhammad) some information of what happened before. And indeed We have given you from Us a Reminder (this Qur'an). Whoever turns away from it (this Qur'an - i.e. does not believe in it, nor acts on its orders), verily, they will bear a heavy burden (of sins) on the Day of Resurrection. They will abide in that (state in the Fire of Hell), and evil indeed will it be that load for them on the Day of Resurrection. Surah 20:99-101
The story of Joseph moves in a stream from beginning to end; its substance and form are equally coherent. It inspires you with a feeling for the depth of Allah's power and supremacy and the execution of His rulings despite the challenge of human intervention. And Allah has full power and control over His Affairs, but most of men know not. Surah 12: 21
This is what the story of Joseph confirms categorically, for it ends with comfort and marvels.