The Peru–Bolivian Confederation was opposed by neighboring countries from its inception, particularly Chile and Argentina, as a potential military and economic threat, and for its support for dissidents in exile. The War of the Confederation was triggered shortly after its formation when Chile and Argentina independently invaded the country. Argentina was defeated in 1837, but a combined force of Chile and North Peruvian dissidents known as the United Restoration Army were victorious at the Battle of Yungay in January 1839, which "de facto" ended the confederation as Peru and Bolivia were restored as independent states, and Santa Cruz fled into exile. The Peru–Bolivian Confederation was officially declared dissolved on August 25, 1839, by General Agustín Gamarra after his appointment as President of Peru.