In the case of Tripoli, the US had been paying an annual tribute to the Pasha of Tripoli in order to avoid conflict, but in 1801, the Pasha demanded a significant increase in the tribute. President Thomas Jefferson refused this demand and instead decided to take military action.
US Navy ships under the command of Commodore Edward Preble sailed to the Mediterranean Sea and began a blockade of Tripoli. The goal was to capture or force Tripoli to surrender and accept the US's terms. During this blockade, the US Navy captured the Tripolitan frigate Philadelphia, which had run aground in the harbor.
In 1804, a group of US Marines led by Lieutenant Presley O'Bannon launched a daring night raid on Tripoli and successfully raised the US flag over the fortress of Derna. This victory demonstrated the US's determination and strength and contributed to the pressure on Tripoli to negotiate a peace treaty.
Ultimately, the US and Tripoli signed a peace treaty in 1805. Tripoli agreed to release all American prisoners and to stop demanding tribute from the United States. The treaty also established a peace and friendship agreement between the two countries.