Independence was proclaimed in 1809, but sixteen years of struggle followed before the establishment of the republic, named for Simón Bolívar, on August 6, 1825 (see Bolivian War of Independence).
In 1836, Bolivia, under the rule of Marshal Andres de Santa Cruz, invaded Peru to reinstall the deposed president, General Luis Orbegoso. Peru and Bolivia formed the Peru-Bolivian Confederation, with de Santa Cruz as the Supreme Protector. Following tensions between the Confederation and Chile, war was declared by Chile on December 28, 1836. Argentina, Chile's ally, declared war on the Confederation on May 9, 1837. The Peruvian-Bolivian forces achieved several major victories; the defeat of the Argentinian expedition, and the defeat of the first Chilean expedition, on the fields of Paucarpata, near the city of Arequipa. On the same field the Paucarpata Treaty was signed with the unconditional surrender of the Chilean and Peruvian rebel army. The treaty assured the Chilean withdrawal from Peru-Bolivia, the return of captured Confederate ships, normalized economic relations, and the payment of Peruvian debt to Chile by the Confederation. Public outrage over the treaty forced the government to reject it. The Chileans organized a second expeditionary force, and attacked the Peru-Bolivian confederation, defeating the Confederation on the fields of Yungay using the same arms and equipment Santa Cruz had allowed them to retain. After this defeat, Santa Cruz fled Ecuador, and the Peruvian-Bolivian Confederation was dissolved.