The following excerpt is taken from islamqa (link):
With regard to the reason why the Prophet (peace and blessings of Allaah be upon him) fasted on the day of ‘Ashoora’ and urged the people to do likewise is mentioned in the hadeeth narrated by al-Bukhaari (1865) from Ibn ‘Abbaas (may Allaah be pleased with him), who said: The Prophet (peace and blessings of Allaah be upon him) came to Madeenah and saw the Jews fasting on the day of ‘Ashoora’. He said, “What is this?” They said, “This is a good day, this is the day when Allaah saved the Children of Israel from their enemy and Moosa fasted on this day.” He said, “We are closer to Moosa than you.” So he fasted on this day and told the people to fast.
The words “this is a good day” – according to a version narrated by Muslim, “This is a great day when Allaah saved Moosa and his people and drowned Pharaoh and his people.”
The words “so Moosa fasted on this day” – Muslim added in his report: “In gratitude to Allaah, so that is we fast on this day.”
According to another version narrated by al-Bukhaari, “So we fast it out of respect for it.”
The words “and told the people to fast” – according to another version narrated by al-Bukhaari, “He said to his companions, ‘You are closer to Moosa than them, so fast this day.”