Spain (and other European countries) was invaded by Napoleon of France. Britain sent troops to defend the peninsula, since it was so weak. Most of the Spanish Empire became independent in the following decades.