In 1812, Zavala created the King's Cavalry Company and was promoted to the rank of lieutenant colonel in the Royal Army. In 1819, he was appointed colonel of the Battalion of Spaniards. During the War of Independence, he defended the Callao, Chancay and Ancón ports in 1820 and 1821. Zavala supported the Aznapuquio mutiny that deposed the Viceroy and was commissioned to inform the King of the situation by the new viceroy José de la Serna. However, his mission was abruptly delayed since the brigantine "Maypú" in which Zavala was transported was captured by an Argentinian frigate in June 1821.