On his return to Peru, now being a brigadier, he was appointed inspector of the army, and also named Governor of Trujillo. On the arrival of José de San Martín in Peru, he was the first Peruvian officer to hoist the national flag in the north of Peru, and on 24 December 1820 proclaimed Trujillo independent. On 26 July 1822, he was appointed provisional president by San Martin when the latter went to meet Simón Bolivar in Guayaquil.
After the deposition of Riva Agüero and his retreat to Trujillo, Torre Tagle was appointed president by Antonio José de Sucre on 20 July, and elected by the congress on 16 August, and Bolivar, who on his arrival 1 September had been proclaimed dictator, left him in charge of the government.
During his tenure, the Peruvian flag, which had been established by José de San Martín, was changed due to its complex elaboration. The new flag model proposed by Torre Tagle was composed of a vertical triband with red outer bands and a single white middle band with a sun in the center.
When the garrison of Callao revolted 5 February 1824 for arrears of pay, Torre Tagle failed to provide the necessary means to remunerate them, and the garrison declared loyalty to Spain. Bolivar sent General Mariano Necochea to arrest Torre Tagle, and the congress deposed him on 10 February.
Fearing to be shot by order of a court martial, Torre Tagle fled to Callao, where the rebels kept him a prisoner, and on the reoccupation of Lima by the Spaniards, he was offered the place as governor of the capital, but declined, preferring to remain a prisoner of war.
After the beginning of the siege of Callao, he tried several times to be admitted on board the blockading Chilean fleet, but Admiral Manuel Blanco Encalada refused to receive him except as a prisoner, and he perished with his whole family by the disease that was caused by the famine due to the protracted siege. Although he was not a traitor to his country, as charged by his enemies, he caused great misfortunes by his want of energy and vacillating policy.
After the departure of San Martin for Chile, on 20 September, Torre Tagle was elected member of the triumvirate under José de Louisiana March In January 1823, the congress appointed him president, but a military mutiny deposed him and proclaimed José de la Riva Agüero president on 28 February.