The Messenger of Allah ﷺ said, "A man who had never done a single good deed said to his family, 'When I die, burn my body, then scatter half of my ashes on land and half in the sea, for by Allah, if Allah gains power over me, He will punish me with a punishment He has never inflicted on anyone in all the worlds.'When the man died, his family did as he had instructed. Allah then commanded the land to gather what it contained, and He commanded the sea to gather what it contained.Then Allah asked him, 'Why did you do this?'He answered, 'Out of fear of You, my Lord, and You know best.'So Allah forgave him."
أن رسول الله ﷺ قال: قال رجل لم يعمل حسنة قط لأهله: إذا مات فحرقوه ثم اذروا نصفه في البر، ونصفه في البحر، فوالله لئن قدر الله عليه ليعذبنه عذابا لا يعذبه أحدا من العالمين، فلما مات الرجل فعلوا ما أمرهم به فأمر الله البر فجمع ما فيه، وأمر البحر فجمع ما فيه، ثم قال: لم فعلت هذا؟ قال: من خشيتك يا رب وأنت أعلم. قال: فغفر له.
Malik narrated it in the Book of Funerals (52) from Abu Zinad, from Araj, from Abu Hurairah, and he related the hadith. Bukhari narrated it in the Book of Tawhid (7506), and Muslim in the Book of Repentance (2756), both from the hadith of Malik, with his chain of transmission, similarly.