The Messenger of Allah ﷺ used to launch raids at dawn. He would listen for the call to prayer, and if he heard one, he would hold back, otherwise he would attack. He heard a man say, "Allah is the greatest, Allah is the greatest," and the Messenger of Allah ﷺ said, "Upon the natural way."Then the man said, "I bear witness that there is no god but Allah, I bear witness that there is no god but Allah," and the Messenger of Allah ﷺ said, "You have come out of the Fire."They looked, and found him to be a goat herder.
كان رسول الله ﷺ يغير إذا طلع الفجر، وكان يستمع الأذان، فإن سمع أذانا أمسك وإلا أغار، فسمع رجلا يقول: الله أكبر الله أكبر، فقال رسول الله ﷺ: على الفطرة. ثم قال: أشهد أن لا إله إلا الله، أشهد أن لا إله إلا الله، فقال رسول الله ﷺ: خرجت من النار. فنظروا فإذا هو راعي معزى.
Muslim narrated it in the Prayer chapter (382) via Hammad bin Salama, who said, Thabit narrated to us, from Anas, and he mentioned it. Bukhari narrated it in the Jihad chapter (2943) through another route from Anas, in abridged form.