Mishkat al-Masabih
The Offices of Commander and Qadi — Hadith #3558
وَعَنْ مُعَاوِيَةَ قَالَ: قَالَ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ: «يَا مُعَاوِيَةُ إِنْ وُلِّيتَ أَمْرًا فَاتَّقِ اللَّهَ وَاعْدِلْ» . قَالَ: فَمَا زِلْتُ أَظُنُّ أَنِّي مُبْتَلًى بِعَمَلٍ لِقَوْلِ النَّبِيِّ صَلَّى الله عَلَيْهِ وَسلم حَتَّى ابْتليت
Mu’awiya reported God’s Messenger as saying, “If you are put in a position of authority, Mu’awiya, fear God and act justly.” He said that he kept thinking he would be afflicted by a governorship in accordance with what the Prophet had said till it actually came true.
Ahmad. Baihaqi transmitted Mu‘awiya’s tradition in Dalail an-nubuwa.