Peru was heavily indebted, and political in-fighting was again on the rise. Peru embarked on a railroad-building program that helped but also bankrupted the country. In 1879, Peru entered the War of the Pacific which lasted until 1884. Bolivia invoked its alliance with Peru against Chile. The Peruvian Government tried to mediate the dispute by sending a diplomatic team to negotiate with the Chilean government, but the committee concluded that war was inevitable. Chile declared war on 5 April 1879. Almost five years of war ended with the loss of the department of Tarapacá and the provinces of Tacna and Arica,
First Upper Peru campaign into a formal agreement, which would imply recognition of the Junta as a legitimate interlocutor. Goyeneche agreed to sign an armistice for 40 days until Lima was issued, and used that time to be strengthened. On 19 June, with the truce still in effect, an advanced royalist troop attacked positions at Juraicoragua. Castelli declared the truce broken and declared war on Peru. The royalist army crossed the Desaguadero on June 20, 1811, starting the Battle of Huaqui. The Army waited near Huaqui, between the plains of Azapanal and Lake Titicaca. The patriotic left wing, commanded by Diaz Velez, faced the