Because Joseph remained loyal to God, he was rewarded with blessings that resulted in the preservation of life both for the Israelites and for the Egyptians.
بَعْدَ سَنَوَاتٍ ،‏ أَخْرَجَهُ فِرْعَوْنُ مِنَ ٱلسِّجْنِ وَعُيِّنَ ٱلْحَاكِمَ ٱلثَّانِيَ فِي مِصْرَ .‏