The Messenger of Allah ﷺ said, "While a man was walking along a road, he became overcome with thirst. He found a well, climbed down into it, drank, and came out. There he saw a dog panting and licking the moist earth from thirst. The man said to himself, 'This dog has reached the same state of thirst that had overcome me.' So he climbed back down into the well, filled his leather sock with water, held it in his mouth until he climbed back up, and gave the dog to drink. Allah thanked him for it and forgave him."The companions asked, "Messenger of Allah, do we have a reward even for animals?"He replied, "In every living creature with a moist liver there is a reward."
أن رسول الله ﷺ قال: بينما رجل يمشي بطريق، إذ اشتد عليه العطش، فوجد بئرا، فنزل فيها فشرب، وخرج، فإذا كلب يلهث، يأكل الثرى من العطش، فقال الرجل: لقد بلغ هذا الكلب من العطش مثل الذي بلغ مني، فنزل البئر، فملأ خفه، ثم أمسكه بفيه، حتى رقي، فسقى الكلب، فشكر الله له فغفر له، فقالوا: يا رسول الله، وإن لنا في البهائم لأجرا؟ فقال: في كل كبد رطبة أجر.
Malik narrated it in "Description of the Prophet" ﷺ (23) from Sumayy, the freedman of Abu Bakr, from Abu Salih Samman, from Abu Hurairah, and he related it.Bukhari narrated it in "Musaqat" (2363), and Muslim in "Salam" (2244), both through the route of Malik, with the same wording.