It was recorded by Muslim (8/94) and Aḥmad (2/308) from Yazīd ibn al-Aṣamm from Abū Hurayrah as a marfūʿ ḥadīth. There are two other chains of transmission from Abū Hurayrah, and many supporting narrations. See: "If you did not err" (no. 969) and (970) and others. Among them is the ḥadīth that follows it and after the ḥadīths numbered (1963), and I mentioned there a brief explanation of the intended meaning of these ḥadīths.
أخرجه مسلم (٨ / ٩٤) وأحمد (٢ / ٣٠٨) عن يزيد بن الأصم عن أبي هريرة مرفوعا. وله طريقان آخران عن أبي هريرة، وشواهد كثيرة، فانظر: " لو أنكم لا تخطؤن " (رقم - ٩٦٩) و (٩٧٠) وغيرهما. ومنها الحديث الآتي بعده وبعد أحاديث برقم (١٩٦٣) ، وذكرت هناك كليمة في المراد من هذه الأحاديث.
"by Him in whose hand is my soul—or he said: by Him in whose hand is Muḥammad's soul—if you were to err until your sins filled what is between the heaven and the earth, then you sought forgiveness from Allāh, He would forgive you. By Him in whose hand is Muḥammad's soul—or he said: by Him in whose hand is my soul—if you did not err, Allāh would bring a people who would err, then seek forgiveness from Allāh, and He would forgive them." It was recorded by Aḥmad (3/238). Suraij ibn al-Nuʿmān narrated to us, Abū ʿUbaidah, meaning ʿAbd al-Muʾmin ibn ʿUbaid Allāh al-Sadūsī, narrated to us. Akhsham al-Sadūsī said: I entered upon Anas ibn Mālik who said: I heard the Messenger of Allāh (ṣallá Allāhu ʿalayhi wa-sallam) say: and he mentioned it. Al-Haythamī said: (10/215): "It was narrated by Aḥmad and Abū Yaʿlá, and its narrators are trustworthy." Thus he said, and it is correct except for this Akhsham, as no one besides Ibn Ḥibbān declared him trustworthy, and he said in "al-Ikmāl": "He is unknown." Al-Ḥāfiẓ said in "al-Taʿjīl": "Neither al-Bukhārī nor Ibn Abī Ḥātim mentioned any criticism of him, and he explicitly stated in his narration that he heard from Anas. And for the ḥadīth that Aḥmad recorded for him regarding seeking forgiveness, there is supporting evidence from the ḥadīth of Abū Hurayrah in Muslim." I said: meaning the ḥadīth before this, and it is only a supporting evidence for the second part of it. As for the first part, there is another chain from Anas similar to it, and its wording is:
" والذي نفسي بيده - أو قال: والذي نفس محمد بيده - لو أخطأتم حتى تملأ خطاياكم ما بين السماء والأرض، ثم استغفرتم الله ﷿ لغفر لكم، والذي نفس محمد بيده - أو قال: والذي نفسي بيده - لو لم تخطئوا لجاء الله ﷿ بقوم يخطئون ثم يستغفرون الله فيغفر لهم ". أخرجه أحمد (٣ / ٢٣٨) حدثنا سريج بن النعمان حدثنا أبو عبيدة يعني عبد المؤمن بن عبيد الله السدوسي حدثني أخشم السدوسي قال: دخلت على أنس بن مالك قال: سمعت رسول الله ﷺ يقول: فذكره. قال الهيثمي: (١٠ / ٢١٥) : " رواه أحمد وأبو يعلى، ورجاله ثقات ". كذا قال، وهو صواب إلا في أخشم هذا، فإنه لم يوثقه سوى ابن حبان، وقد قال في " الإكمال ": " هو مجهول ". وقال الحافظ في " التعجيل ": " لم يذكر البخاري ولا ابن أبي حاتم فيه جرحا، وصرح في روايته بسماعه من أنس، وللحديث الذي أخرجه له أحمد في الاستغفار شاهد من حديث أبي هريرة عند مسلم ". قلت: يعني الحديث الذي قبل هذا وإنما هو شاهد للشطر الثاني منه وأما الشطر الأول، فله طريق أخرى عن أنس بنحوه، ولفظه: