The key factor that finally led to the decline of Barbary piracy was:
A) The United States' decisive victory over the Barbary states.
This is primarily due to military actions taken by the U.S. in the early 19th century, particularly the First Barbary War (1801-1805) and the Second Barbary War (1815), which significantly weakened the power of the Barbary states and reduced pirate activity in the Mediterranean.