Gamarra had a military life since childhood, battling against the royalist forces. He then joined the cause of Independence as second in command after Andrés de Santa Cruz. He also participated in the Battle of Ayacucho, and was later named Chief of State. After the invasion of Bolivia in 1828, he was named a mariscal, a highly-esteemed military officer.
After the defeat of José de la Mar in Gran Colombia, Gamarra urged his overthrow and assumed the presidency for a brief period after Antonio Gutiérrez de la Fuente. The peace treaty with Gran Colombia was also signed during Gamarra's government.
Gamarra finished, with great effort, his first constitutional government. He had a very active character which allowed him to leave Lima to thwart rebellions in various parts of the country. During such expeditions he would leave the presidency to Antonio Gutiérrez de la Fuente, who manifested his authoritarian character and started to receive the enmity of other government officials based in Lima.
During his second government, Gamarra confronted the challenge of pacifying the country in middle of various subversions while at the same time the beginning of a war against Bolivia. Gamarra was defeated and killed by Bolivian forces during the Battle of Ingavi in 1841.