I did a little checking on that and what I read was we paid ransom to release enslaved sailors. In the end our fledgling navy defeated Tripoli and Algiers and we never paid them again. I'm no historian and may have it wrong but sure liked the fact they were extorting us so we crushed them militarily. A feel good story.