Between 1801 and 1805, the United States fought a war against North African corsairs. Piracy was an important part of Morocco, Algeria, Tunis and Tripoli's history which was not really appreciated by the Americans. During the 19th century, corsairs were the scourge of the Mediterranean Sea as they ruled North Africa's most powerful states. In Morocco, pirates and their ships were governed by the Alaouite dynasty after their famous short-lived republic collapsed in the 17th century. Their counterparts in Algeria, Tunis and Tripoli operated under the auspices of the Ottoman Empire. The four powers were dubbed Barbary states by the United States. Living on blackmailing, Morocco, Algeria, Tunisia and Libya «received great sums of money, ships, and arms yearly from foreign powers in return for allowing the foreigners to trade in African ports and sail unmolested through the Barbary waters», recalled US Wars, a platform specialized in the battles on wars fought by America. The First Barbary War The money generated from piracy contributed to the economy of these states, indicate historical accounts. But the practice led later to a war between the United States and the four states after a series of offences that targeted ships ruled by the newly founded country. Fought between 1801 and 1805, the war was dubbed the «First Barbary War» which was «an undeclared war waged by the United States against the North African states of Morocco, Tripoli, Algiers, and Tunis». According to the same source, «the principle cause of the war was that those states harbored and supported the actions of pirates against American shipping vessels in the Mediterranean Sea». But although, the war did not stop piracy in the Maghreb region, it led to the signing of a treaty between Morocco and the United States. Negotiations between Morocco and the United States started way before the Barbary War broke out. On October the 11th 1784, Alaouite sultan Mohammed III detained an American merchant ship named Betsey in Tangier and ordered the American government to sign a treaty in exchange of the men, ship and cargo. Indeed, in 1785, a treaty between the USA and Morocco was under negotiation and the Sultan released the Bestey crew and shipment, making of the country one of the first Barbary states to protect American ships in the Barbary waters. However, convincing Algeria into signing a similar treaty was a hard task for American diplomats at the time. According to the Thomas Jefferson Foundation, «Algiers was much more dependent than Morocco on the fruits of corsairing — captured goods, slaves, the ransoms they brought, and tribute — and less amenable to a peace treaty with the United States». «During these years American vessels in the Mediterranean sailed in convoy with European ships (…) in the Atlantic, the Morocco treaty provided protection from Moroccan corsairs and the Portuguese navy kept those from Algiers, Tunis and Tripoli in the Mediterranean». Thomas Jefferson Foundation But although Morocco promised to protect American ships under a treaty signed by sultan Mohammed III, the name of Moulay Slimane was among the rulers who fought the First Barbary War. Sultan Slimane, who ruled Morocco from 1792 to 1822, had reportedly participated as a commander to the war next to Yusuf Karmanli, Rais Mahomet Rous, Hassan Bey and Shadi Nazmi Reis, off the Mediterranean coast of Tripoli. After the First Barbary War, American ships fought a second one against Tripoli and Tunis. Morocco, however, was not part of the Second Barbary War as sultan Slimane has abolished piracy and preferred to maintain good diplomatic relations with the United States.