Answer:
The United States refused to pay Tripoli a tribute to guarantee safe passage for American ships.
Pirates from the Barbary States attacked American ships.
Step-by-step explanation:
Tripoli is located on the north part of Africa. Since it's directly bordered the ocean route, United States traders had no choice but to pass through this territory if they want to distribute their products to the rest of African region.
Tripoli knew this and require American Ships to pay some sort of "Tribute" if they wanted to pass their territory. Officials in Jefferson presidency saw this as an act of harassment and refuse to pay it.
As a result, Tripoli "look the other way" when the Pirates who operated in their territory attacked American Ships. This is why the war between US and Tripoli started.