Spain, a major European power from the 16th through 18th century, had been active on the western North African coast. Its government was constantly scheming with local powers, occupying port cities, installing, and maintaining puppets. Spain has lost most of those African enclaves, but it still has a presence in Africa to this day (notably Ceuta and Mellila, both on the African continent, both claimed by Morocco).
The local Amirs found themselves outgunned by the Spanish, and there was, therefore, some sympathy for the idea that the Muslim Ottomans, led by the Caliph, would be welcome, should they decide to get involved.
Not everyone agreed. The Ottomans were Turks, which is to say, foreigners. Everyone knew that the Ottoman system featured ethnic supremacy as a guiding principle. Turks would always rule, they would decide what people of other ethnicities would do. When the Ottomans did get involved, they established positions from Egypt to Algeria. They never got a foothold in Morocco, though.
The way the Ottomans did things was basically that only Turks could rule, so they sent out governors from Constantinople. Because of the constant tendency for the local rulers to become autonomous and dynastic, the Ottoman governors in North Africa became substantially independent in the 19th century. That meant that while formal vassal relationships were maintained with the Sultan in Constantinople, the