In the early 19th century, while most South American nations were swept by wars of independence, Peru remained a royalist stronghold. As the elite vacillated between emancipation and loyalty to the Spanish Monarchy, independence was achieved only after the occupation by military campaigns of José de San Martín and Simón Bolívar.