in 1819, Viceroy La Pezuela prevented him from exercising his position as Intendant of La Paz. In return, the viceroy first appointed him his aide-de-camp and then interim Intendant of Lima. Tagle remarried Mariana Echevarría y Santiago de Ulloa. In 1820, he was appointed Intendant of Trujillo and when José de San Martín entered into 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. After the independence was proclaimed by San Martín in July 1821, Tagle was appointed General Inspector of the Civic Guard and Commander-in-Chief of the Peruvian Legion. One of the closest allies of San Martín, he was designated a member of the Council of State and created a Founder of the Order of the Sun, of whose Grand Council he was vice president. 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 departure of San Martin for Chile, on 20 September, Torre Tagle was elected member of the triumvirate under José de La Mar. 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. 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