Castelli was appointed a Committee member of the Primera Junta and was sent to Córdoba to end Santiago de Liniers's counter-revolution. He succeeded, and ordered the execution of Liniers and his supporters. He then commanded the establishment of a revolutionary government in Upper Peru (today's Bolivia) with the aim of freeing the indigenous peoples and African slaves. In 1811 Castelli signed a truce with the Spanish in Upper Peru, but they betrayed him and caught the Northern Army unprepared. As a result, the Argentines suffered a major loss in the Battle of Huaqui on 20 June 1811. When Castelli returned to Buenos Aires, the First Triumvirate imprisoned him for losing the battle, and Castelli died shortly afterwards from tongue cancer.