The first and second Barbary Wars of the early 19th century were the first nominal foreign wars waged by the United States post-Independence. Directed against the Barbary States of North Africa, the Barbary Wars were fought to end piracy against American-flagged ships in the Mediterranean Sea, similar to the Quasi-War with the French Republic.