The War of the Confederation was a war fought between an alliance of Chile, Argentina, and the Restoration Army of Peru and the forces of the Peru-Bolivian Confederation. The war resulted in the dissolution of the union between Peru and Bolivia, and those two countries would experience tensions until Peru's defeat in the Peruvian-Bolivian War of 1841-42.
Peru's civil war of 1835-1836 resulted in the execution of the conservative, Chile and Argentina-backed President Felipe Santiago Salaverry after the Bolivian president Andres de Santa Cruz intervened to support his liberal ally in Peru, Luis Jose de Orbegoso. After the civil war was won, Santa Cruz and Orbegoso merged their two countries into the Peru-Bolivian Confederation, alarming the Chilean statesman Diego Portales, who was concerned that the new confederacy would break the regional balance of power and even threaten Chilean independence.
On 14 February 1836, Peru nullified the late Salaverry's free trade agreement with Chile, causing Chile to raise tariffs on Peruvian sugar. That same year, the former Chilean president Ramon Freire attempted to seize power from President Jose Joaquin Prieto with backing from Peru, but the Chileans captured Freire's ship and thwarted his attempt to capture Ancud. Portales responded by ordering the Chilean Navy to attack the Confederate fleet at the Peruvian port of Callao on 21 August 1836, capturing three ships. On 28 December 1836, Chile declared war on the Confederation after Santa Cruz refused to dissolve the Confederation. Argentina and Ecuador initially decided to remain neutral, but Santa Cruz's support of the Argentine Unitarios motivated the Argentine caudillo Juan Manuel de Rosas to join the war on Chile's side on 9 May 1837. Peru's ally, France, responded by blockading Buenos Aires, but they failed to remove Rosas from power.
Chile's imposition of martial law and the unpopularity of the war with Peru-Bolivia resulted in Portales' assassination on 6 June 1837 during a failed coup led by Jose Antonio Vidaurre, but the coup backfired and made Portales into a martyr. The Confederates were able to capture the Juan Fernandez Islands in November 1837, and a Chilean army sent to capture Arequipa found itself blockaded by the Peruvian Navy shortly after taking the city. The Chilean admiral Manuel Blanco Encalada was forced to sign a peace treaty with Peru on 17 November 1837, and the Chileans evacuated Peru. The Chilean government, backed by the public, repudiated the treaty in December 1837 and had Blanco tried for high treason, ultimately acquitting him. The Chilean Navy fought the Peruvians to a standstill at the Battle of Islay on 12 January 1838, but, by mid-1838, Chile had obtained naval superiority. General Manuel Bulnes led an army north to besiege Lima, defeating the Confederates at the Battle of Portada de Guias on 21 August 1838. Though Lima was briefly occupied by Chile in October, the Chileans withdrew on Santa Cruz's approach in November. At the same time, the citizens of Peru revolted against the Confederation and proclaimed Agustin Gamarra as their President. Orbegoso also broke with Santa Cruz and rebelled against him without Chilean support in 1838, but he was defeated by Chilean forces and his short-lived Peruvian Republic was defeated. Argentina did not achieve any significant advance from 1837 to 1838, losing some territories north of Jujuy.
The Chileans won another victory at the Battle of Casma on 12 January 1839, leaving the Chilean Navy in control of the southeastern Pacific. On 20 January 1839, Santa Cruz finally caught up with the Chilean expedition at the Battle of Yungay. In the ensuing battle, the Chileans crushed the Confederates, and Bulnes reoccupied Lima. Santa Cruz was forced to flee to Ecuador, and the Peru-Bolivian Confederation was dissolved by Gamarra on 25 August 1839. Gamarra declared the merger of North Peru and South Peru, and Chilean troops departed on 19 October 1839. However, Gamarra decided to pursue the war against Bolivia on his own, seeking to create a confederation dominated by Peru instead of Bolivia. He was killed at the Battle of Ingavi on 20 November 1841, and Peru and Bolivia made peace in 1842.