[3] He studied at the "La Libertad" national school, graduating in 1843 and became a cadet in the army organized by Marshal Domingo Nieto of Moquegua.
[3] When, in 1854, Marshal Castilla's revolution against President José Rufino Echenique began, he held the rank of captain, participating in the battle of La Palma and rising to sergeant major during the campaign.
In 1864 he supported the constitutional government of President Juan Antonio Pezet and he marched to fight the Arequipa revolution led by General Mariano Ignacio Prado, occupying Arica but Lima was captured by the revolutionaries and overthrowing the Pezet administration and Gastó accepted the new authorities, participating in 1867 of the frustrated siege and attack on the city of Misti.
[3] After returning to Lima in disguise to settle personal matters, he went back to the Andes Mountains to join the Sierra campaign led by General Andrés Cáceres, whom he represented as a special envoy to the Arequipa government, which was then chaired by Colonel La Torre, reintegrated into the resistance army and then took part in the 1882 counteroffensive against the forces of Chilean Colonel Estanislao del Canto.
[3] He continued the campaign until the withdrawal of the occupying Chilean forces and the following year he made the march north that would culminate in the disastrous defeat at the Battle of Huamachuco in which he met his death.