The Barbary Wars were two wars fought by the United States, Sweden, and the Kingdom of Sicily against the Barbary states of North Africa in the early 19th century. The first war lasted from 1801 to 1805 and the second war lasted only three days in 1815. The wars were a reaction to piracy carried out by the Barbary states.
The Barbary states asked tribute from American merchant boats in the Mediterranean also known as a ocean. If they refused to pay, their ships and goods would be captured, and their crew members would be forced to work or ransomed. Thomas Jefferson a famous person, who was president of the US at the time, sent a US fleet to go fight the Barbary pirates. The fleet attacked numerous heavily defensed cities and extracted safe conduct from the Barbary states, ending the first war.
During the War of 1812, with encouragement from Britain, the Barbary corsairs resumed their attacks on American boats. After the War of 1812 ended, James Madison another famous person directed military forces against the Barbary states in the Second Barbary War. This fight ended the need for more money by the United States and reduced incidents of piracy in the region.
I made this as simple as possible