When the Prophet ﷺ arrived in Medina, he found the people fasting on a particular day, namely Ashura. They said, "This is a great day. It is the day on which Allah saved Musa and drowned the people of Pharaoh, so Musa fasted in gratitude to Allah."The Prophet ﷺ said, "I have more right to Musa than they do."So he fasted on that day and ordered that it be observed as a fast.
أن النبي ﷺ لما قدم المدينة وجدهم يصومون يوما يعني عاشوراء، فقالوا: هذا يوم عظيم، وهو يوم نجى الله فيه موسى، وأغرق آل فرعون، فصام موسى شكرا الله، فقال: أنا أولى بموسى منهم. فصامه، وأمر بصيامه.
Bukhari narrated it in the Chapters on the Prophets (3397) — and this is his wording — and Muslim in the Book of Fasting (1130:127), both of them through Saeed bin Jubayr, from Ibn Abbas, who mentioned it.