The Messenger of Allah ﷺ said, "One of the prophets stopped to rest under a tree, and an ant bit him. He ordered his belongings to be removed from beneath it, then commanded that the ant's nest be burned with fire. Allah revealed to him, 'Why not just a single ant?'"
أن رسول الله ﷺ قال: نزل نبي من الأنبياء تحت شجرة، فلدغته نملة، فأمر بجهازه فأخرج من تحتها، ثم أمر ببيتها فأحرق بالنار، فأوحى الله إليه: فهلا نملة واحدة.
Bukhari narrated it in the Beginning of Creation (3319), and Muslim in the Chapter on Greetings (2241:149), both from Abu Zinad, from Araj, from Abu Hurairah, as mentioned.On this subject, there is also what Abu Dawud narrated (2675, 5268) from Mahbub bin Musa, who said, Abu Ishaq Fazari informed us, from Abu Ishaq Shaybani, from Ibn Saad (that is, Hasan bin Saad), from Abdul-Rahman bin Abdullah, from his father, who said, We were with the Messenger of Allah ﷺ on a journey, and he went off to relieve himself. We saw a small bird with two chicks, so we took her chicks, and the bird came and began flapping about in distress. The Prophet ﷺ came and said, "Who has distressed this bird over her young? Return her young to her." He also saw an anthill that we had burned, and he said, "Who burned this?" We said, "We did." He said, "It is not fitting that anyone should punish with fire except the Lord of fire."Bukhari narrated it in Adab al-Mufrad (382), and Hakim (4/239), both through routes from Hasan bin Saad, with the wording confined to the story of the bird. Ahmad (4018) and Nasai in Kubra (8560) both narrated it through the route of Abu Ishaq Shaybani, with the wording confined to the story of burning the anthill.Whether Abdul-Rahman bin Abdullah bin Masud actually heard from his father is a matter of dispute, and the more likely view is that he heard only four hadiths from his father, and this is not one of them.