The viceroy often had the support of the "Lima oligarchy," who saw their elite interests threatened by popular rebellion and were opposed to the new commercial class in Buenos Aires.
The Spanish Empire's central authority was lost during the 1807–1814 Peninsular War, and many regions established autonomous local administrations known as juntas.
Because of this, Peru remained strongly royalist and participated in the political reforms implemented by the Cortes of Cádiz (1810–1814) despite Abascal's resistance.
[3] Peru eventually succumbed to patriot armies after the decisive continental campaigns of José de San Martín (1820–1823) and Simón Bolívar (1823–1825).
The root cause of indigenous discontent remained, however, and whether these movements should be considered precedents of the broader emancipation led by chiefs (caudillos), Peruvian towns (pueblos), and other American countries is a subject of debate.
The campaign of Sucre in Upper Peru concluded in April 1825 and, in November of that year, Mexico obtained the surrender of the Spanish bastion of San Juan de Ulúa in North America.
Native juntas emerged despite Peru's royalist tendencies, often fomented by the approach of rebel armies from Buenos Aires.
Criollo leaders appealed to retired brigadier Mateo Pumacahua, curaca of Chinchero, who was instrumental in suppressing the rebellion of Túpac Amaru II decades earlier.
Pumacahua joined the Criollo leaders, forming a junta in Cuzco on August 3 which demanded the implementation of the Spanish Constitution of 1812's liberal reforms.
After victories in southern and Upper Peru, the rebellion was quashed by mid-1815; the combined strength of royal forces and loyal curacas, including the Catacora and Apo Cari, took Cuzco and executed Pumacahua.
[4] After quashing the rebellion, the Viceroy of Peru organized two expeditions against Chile made up of royalist regiments from Lima and Arequipa and expeditionary elements from Europe.
Hostilities began with a campaign in the Peruvian highlands led by General Juan Antonio Álvarez de Arenales from October 4, 1820, to January 8, 1821.
Arenales rejoined General San Martín in Huaura, and proclaimed the independence of the city of Huamanga (Ayacucho) on November 1, 1820.
The new viceroy announced his departure from Lima on June 5, 1821, but ordered a garrison to resist the patriots in the Real Felipe Fortress; this led to the first siege of Callao.
Cochrane was welcomed into Lima two days later, and San Martín proclaimed independence in the city's Plaza Mayor on July 28, 1821.
San Martín argued for a constitutional monarchy, and Bolivar (head of the Northern Expedition) wanted a republic; both sought independence from Spain.
In the wake of San Martín's self-exile and military defeats under President José de la Riva Agüero, the congress appealed to Simón Bolívar for help in 1823.