The abdication of kings Carlos IV and Fernando VII of Spain and the installation of Napoleon's brother as King José provoked civil wars and revolutions leading to the independence of most of Spain's mainland American colonies. In Spanish America many local elites formed juntas and set up mechanisms to rule in the name of Ferdinand VII, whom they considered the legitimate Spanish monarch. The outbreak of the Spanish American wars of independence in most of the empire was a result of Napoleon's destabilizing actions in Spain and led to the rise of strongmen in the wake of these wars. The defeat of Napoleon at Waterloo in 1815 caused an exodus of French soldiers into Latin America where they joined ranks with the armies of the independence movements. While these officials had a role in various victories such as the Capture of Valdivia (1820) some are held responsible for significant defeats at the hands of the royalist as is the case of Second Battle of Cancha Rayada (1818).