He was taken prisoner after the defeat of Ayohuma on November 14, 1813, and destined for the Casas Matas of Callao jail where he was held for several years. He owed his freedom to a prisoner exchange made by General José de San Martín in 1820. He was rejoined the army that same year serving with the rank of Captain in the Expedición Libertadora del Perú.