The markets declined after Sweden and the United States defeated the Barbary States in the Barbary Wars (1800–1815). A US Navy expedition under Commodore Edward Preble engaged gunboats and fortifications in Tripoli in 1804. A British diplomatic mission to Algiers led to the Dey to agree to release some Sardinian slaves. However, the moment the British left, the Dey ordered the Sardinians massacred; the same fleet joined by some Dutch warships returned and delivered a nine-hour bombardment of Algiers in 1816 leading to the Dey accepting a new agreement in which he promised to end his slavery operations. Despite this, the trade continued, only ending with the French conquest of Algeria (1830–1847). The Kingdom of Morocco had already suppressed piracy and recognized the United States as an independent country in 1776.