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 richest cities of Upper Peru, an open cabildo calls Goyeneche to withdraw from their territory, which he obeys as he did not have military strength to prevail. The Bishop of La Paz, Remigio La Santa y Ortega, flees with him. Castelli is received in Potosí, where he required an oath of allegiance to the Junta and the surrender of the royalist generals Francisco de Paula Sanz and José de Córdoba y Rojas. He arranged that the operation to capture Vicente Nieto was carried out exclusively by the surviving patricians at the mines of Potosi, who had been incorporated with honors