It is narrated from Sayyiduna Ibn Abbas (may Allah be pleased with them both) that the Messenger of Allah (peace and blessings be upon him) said: "A prophet among the prophets complained to his Lord, the Mighty and Majestic, and said: O my Lord! There is a servant among Your servants who believes in You and acts in obedience to You, yet You withhold the world from him and expose him to trials; and there is a servant among Your servants who disbelieves in You and acts in disobedience to You, yet You withhold trials from him and grant him the world. So Allah, the Mighty and Majestic, revealed to him: Indeed, trials and servants are Mine, and there is nothing except that it glorifies Me, declares My oneness and proclaims My greatness. As for My believing servant, he has some sins, so I withhold the world from him and expose him to trials, until he comes to Me (purified) and I reward him for his good deeds. And as for My disbelieving servant, he has some good deeds, so I withhold trials from him and grant him the world, until he comes to Me and I recompense him for his evil deeds."
Hadith Referenceالمعجم الكبير للطبراني / باب العين / 12681