The rise and fall of piracy (1400-1830)

The demise of the Almohad empire created a power vacuum which led to the rise of piracy along what became known as the Barbary Coast. Coastal cities hired corsairs to seize merchant vessels and gain an advantage in the fierce competition for trade on the high seas.
North African piracy compelled the Spanish to occupy and blockade several ports known to be pirate enclaves, including Algiers which was forced to pay tribute. This Christian occupation of North African ports forced Muslims to seek help from the Ottoman Khalif. The Barbarossas, two sibling pirates, petitioned the Ottoman Sultan for aid against the infidels. In response the Khalif sent a naval fleet which drove the Spanish out of most of the North African ports they were occupying.
In 1518 Khayrad'din Barbarossa became the sultan's official representative in Algeria and Algerian corsairs dominated the Mediterranean with Ottoman protection for centuries. It was not until late in the 18th century that Europeans were able to challenge the Barbary pirates of Algeria with superior naval power and artillery. In 1815 a US naval squadron under Captain Stephen Decatur attacked Algiers and forced its governor to sign a treaty banning piracy against US ships.
Persistent attacks on European shipping caused the British and Dutch to combine their forces against the Algerians and almost totally destroy their fleet in 1816. This was the beginning of the end. In 1830 the French army invaded Algiers and the French occupation of Algeria continued for 132 years.