Sahih al-Bukhari, Book 97, Hadith 178 (Bukhari 7267)
Narrated Abu Huraira:
I heard Allah's Messenger (ﷺ) saying, "Before Allah created the creations, He wrote a Book (wherein He has written): My Mercy has preceded my Anger." and that (Book) is written with Him over the Throne."