Hadithcore
Mishkat al-Masabih, 2933

Abu Huraira traced to the Prophet (ﷺ) the statement that God who is great and glorious says, “I make a third with two partners as long as one of them does not cheat the other, but when he cheats him I depart from them." Abu Dawud transmitted it and Razin added, “and the devil comes."

عَن أبي هُرَيْرَة رَفَعَهُ قَالَ:

إِنَّ اللَّهَ عَزَّ وَجَلَّ يَقُولُ: أَنا ثَالِث الشَّرِيكَيْنِ مَا لم يخن صَاحِبَهُ فَإِذَا خَانَهُ خَرَجْتُ مِنْ بَيْنِهِمَا

. رَوَاهُ أَبُو دَاوُد وَزَاد رزين: «وَجَاء الشَّيْطَان»

References1 variant
In-Book Reference
Book 11, Hadith 169