Read The Story of the Barbary Corsairs by Stanley Lane-Poole, published privately 2016, from which the following comments are taken.
“When the Spanish expelled the Moors from Spain in 1492, they did not foresee the consequences. Thousands of Moors, banished from their homeland of seven hundred years, moved across the straits to cities in Africa, especially Algiers, and, driven by the desire for vengeance, began a campaign of piracy and reprisals against the Spanish, which lasted until their base at Algiers was captured by the Spanish in 1518.
“The Moors sought help from the Turkish Barbary Corsairs. Under Corsair leadership, piracy became a scourge of the Mediterranean and beyond.”