The United States Navy was founded, in part, to counter the activities of the Barbary pirates, and the United States fought the First and Second Barbary Wars (1801–1805, 1815) to end this threat to its shipping.