1297. Ottoman rule First Ottoman period In 1517, the first Ottoman period began with Selim I's conquest of Mamluk Egypt. This added Medina to their territory and they continued the tradition of showering Medina with money and aid. In 1532, Suleiman the Magnificent built a secure fortress around the city and constructed a strong castle armed by an Ottoman battalion to protect the city. This is also the period in which many of the Prophet's Mosque's modern features were built even though it wasn't painted green yet. These suburbs also had walls and gates. The Ottoman sultans took a keen interest in the Prophet's Mosque and redesigned it over and over to suit their preferences. First Saudi insurgency As the Ottomans' hold over their domains broke loose, the Madanis pledged alliance to Saud bin Abdulaziz, founder of the First Saudi state in 1805, who quickly took over the city. In 1811, Muhammad Ali Pasha, Ottoman commander and Wali of Egypt, commanded two armies under each of his two sons to seize Medina, the first one, under the elder Towson Pasha, failed to take Medina. But the second one, a larger army under the command of Ibrahim Pasha, succeeded after battling a fierce resistance movement. Muhammad Ali Pasha's era After defeating his Saudi foes, Muhammad Ali Pasha took over governance of Medina and although he did not formally declare independence, his governance took on more of a semi-autonomous style. Muhammad's sons, Towson and Ibrahim, alternated in the governance of the city. Ibrahim renovated the city's walls and the Prophet's Mosque. He established a grand provision distribution center (taqiyya) to distribute food and alms to the needy and Medina lived a period of security and peace. In 1840, Muhammad moved his troops out of the city and officially handed the city to the central Ottoman command. Second Ottoman period Four years in 1844, after Muhammad Ali Pasha's departure, Davud Pasha was given the position of governor of Medina under the Ottoman sultan. Davud was responsible for renovating the Prophet's Mosque on Sultan Abdulmejid I's orders. When Abdul Hamid II assumed power, he made Medina stand out of the desert with a number of modern marvels, including a radio communication station, a power plant for the Prophet's Mosque and its immediate vicinity, a telegraph line between Medina and Constantinople, and the Hejaz railway which ran from Damascus to Medina with a planned extension