First Tosun Pasha led the army in 1811 and occupied Medina in 1812 and Mecca in 1813. After his death İbrahim Pasha, who had accompanied Mehmed Ali's personal visit to the Hejaz in 1814, took over and chased the Wahhabis into the Nejd.[23] Upon the news of the victory, Mahmud II appointed İbrahim Pasha governor of Jeddah and Habeş. He was the nominal ruler of Hejaz on behalf of the Ottomans from 1811 to 1840.[23] The Wahhabi were ousted from the Hejaz in 1818, when Mehmed Ali Pasha, by then Governor of Egypt, was able to succeed in final victory.[23] The Hejaz then fell under his domination.[24] The 1840 Convention of London forced Mehmed Ali to pull out from the Hejaz.[25]