In 1554 the Wattasid Dynasty took Fes with the support of the Turks, and the city became a fairly loose vassal of the Ottomans, but the seaside town of Melilla remained, together with other further East Mediterranean strongholds conquered by the Spaniards going as far as Tripoli in the actual Libya under the military control of the Spaniards to block Ottoman expansion towards the West, the practice of piracy and slave trading and so on.
Melilla was besieged again in 1694–1696 under Ismail Ibn Sharif (reigned 1672–1727), the second ruler of the Alaouite dynasty, the successor of his half-brother Al-Rashid of Morocco.
The expeditionary Spanish force, which departed from Algeciras, was composed of 36,000 men, 65 pieces of artillery, and 41 ships, which included steamships, sailboats, and smaller vessels while Leopoldo O'Donnell, 1st Duke of Tetuan, Prime Minister of Spain, personally took charge of the expedition.
When Mohammed IV died in 1873, Morocco was ready to be "protected" from the covetous eyes of the Spaniards, great losers of the American territories in the 1820s and 1830s by the French, conquerors of Algiers in 1830 and expanding by then further and further south of the Sahara.
The Northern Rif mountains Berbers, however, did not pay much attention to these political concoctions pressurized by the Spanish presence in their lands.