In 854 Muhammad was appointed as governor of Hims after the previous head official Abu al-Mughith Musa ibn Ibrahim was forced out by the inhabitants. In the following year he was faced with a large uprising by the city's inhabitants, which he however defeated with the help of reinforcements from Damascus and Ramla. As a consequence of the revolt he was ordered by the caliph al-Mutawakkil to undertake a number of punitive measures against the city residents, including the execution of a number of local leaders and the expulsion of the entire Christian population from Hims.