Madison, serving as secretary of state under President Jefferson, advocated waging war against the brutes. In 1801, the U.S. refused to hand over any more money, and battles ensued, according to the Montpelier Foundation, whose mission is to preserve Madison’s legacy. By 1805, the Marines had successfully defeated the pirates and the payoffs ceased.
European nations had entered into treaties with the Barbary States whereby they were at peace, but the European nations paid a yearly tribute to ensure the safe release of any hostages taken. The United States chose to not pay, and sent the first marines to battle the corsairs into submission and to release their hostages in the First Barbary War. In the end, the United States won handily and came to a treaty with the Bashaw of Tripoli that ended the war in exchange for ransoming the hostages. The treaty was a questionable triumph for the Jefferson administration and after the war of 1812 a Second Barbary War that included a coalition of European forces along with the US changed the acceptability of the Corsairs in the Mediterranean.
James Madison's is considered the loudest hawkish voice in Jefferson's cabinet that pushed the young country into this battle. His position eventually led to the downfall of the Corsair empires of North Africa.
Today, "the shores of Tripoli" are immortalized in the U.S. Marine Corps's anthem and in monuments such as the Tripoli Monument at the U.S. Naval Academy in Annapolis, Maryland.