Born in Fez, Moulay Muhammad was a son of the Alaouite sultan of Morocco Abd al-Rahman. During his father's reign, Muhammad commanded the Moroccan army which was defeated by the French at the Battle of Isly in August 1844.