When Jefferson became president in 1801 he refused to accede to Tripoli's demands for an immediate payment of $225,000 and an annual payment of $25,000. The pasha of Tripoli then declared war on the United States. Although as secretary of state and vice president he had opposed developing an American navy capable of anything more than coastal defense, President Jefferson dispatched a squadron of naval vessels to the Mediterranean. As he declared in his first annual message to Congress: "To this state of general peace with which we have been blessed, one only exception exists. Tripoli, the least considerable of the Barbary States, had come forward with demands unfounded either in right or in compact, and had permitted itself to denounce war, on our failure to comply before a given day. The style of the demand admitted but one answer. I sent a small squadron of frigates into the Mediterranean. . . ."
The American show of force quickly awed Tunis and Algiers into breaking their alliance with Tripoli. The humiliating loss of the frigate Philadelphia and the capture of her captain and crew in Tripoli in 1803, criticism from his political opponents, and even opposition within his own cabinet did not deter Jefferson from his chosen course during four years of war. The aggressive action of Commodore Edward Preble (1803-4) forced Morocco out of the fight and his five bombardments of Tripoli restored some order to the Mediterranean. However, it was not until 1805, when an American fleet under Commodore John Rogers and a land force raised by an American naval agent to the Barbary powers, Captain William Eaton, threatened to capture Tripoli and install the brother of Tripoli's pasha on the throne, that a treaty brought an end to the hostilities. Negotiated by Tobias Lear, former secretary to President Washington and now consul general in Algiers, the treaty of 1805 still required the United States to pay a ransom of $60,000 for each of the sailors held by the dey of Algiers, and so it went without Senatorial consent until April 1806. Nevertheless, Jefferson was able to report in his sixth annual message to Congress in December 1806 that in addition to the successful completion of the Lewis and Clark expedition, "The states on the coast of Barbary seem generally disposed at present to respect our peace and friendship."
In fact, it was not until the second war with Algiers, in 1815, that naval victories by Commodores William Bainbridge and Stephen Decatur led to treaties ending all tribute payments by the United States. European nations continued annual payments until the 1830s. However, international piracy in Atlantic and Mediterranean waters declined during this time under pressure from the Euro-American nations, who no longer viewed pirate states as mere annoyances during peacetime and potential allies during war.