Mawlay Muhammad bin Abd al-Rahman (), known as Muhammad IV (), born in Fes in 1803 and died in Marrakesh in 1873, was the Sultan of Morocco from 28 August 1859 to 16 September 1873 as a ruler of the 'Alawi dynasty. He was proclaimed sultan after the death of his father, Abd al-Rahman. His reign marked a series of reform to tackle European influence on Morocco, as Ottoman Algeria had just been conquered by France in 1830, leading to European nations entering military conflicts with Morocco, such as the Battle of Isly with France in 1844 and the Battle of Tetuan with Spain in 1860. He was succeeded by his son Hassan I. Biography Military commander Born in 1803 in Fes, Mawlay Muhammad was a son of the 'Alawi sultan of Morocco Abd al-Rahman. During his father's reign, neighbouring Ottoman Algeria was invaded by France in 1830, and Muhammad commanded the Moroccan army which was defeated by the French at the Battle of Isly in August 1844. After the defeat, with his father's permission, Mawlay Muhammad used his capacity as army chief to launch a series of significant military reforms in 1845. He invited a group of officers from Ottoman Tunisia who had served in the Ottoman army to raise and train the first European-style regiment, the askari, as a supplement to the usual palace guards ('abid) and tribal troops ( and ). Muhammad IV set up the Madrasa of al-Muhandiseen, a military engineering school in Fes, supervised by the renegade French Count Joseph de Saulty (an artillery officer from Algiers, de Saulty defected after an amorous entanglement, and converted, taking up the name Abd al-Rahman al-Ali). Muhammad IV hired writers to translate various European textbooks on engineering and science. He was personally involved in the translation of the works of scientists such as Legendre, Newton and Lalande. He also struck deals with British Gibraltar and Egypt to receive regular contingents of Moroccan soldiers for artillery training. Sultan Hispano-Moroccan War Immediately upon ascension to throne in August 1859, Muhammad IV was faced with his first test, the Spanish-Moroccan War under Isabella II of Spain. Raids by irregular tribesmen on the Spanish enclaves of Ceuta and Melilla in northwest Morocco prompted Spain to demand an expansion of the borders of its enclave around Ceuta. When this was refused by Muhammad IV, Spain declared war. The Spanish navy bombarded Tangier, Asilah