When Napoleonic France invaded and occupied Spain during the Peninsular War (1807 – 1814) installing Joseph Bonaparte, Napoleon’s brother, on the Spanish throne, aspirations for independence from Spain developed in the Spanish South American territories mainly fueled and supported by personalities from the wealthy, respected and aristocratic upper class which had their routes in Europe (mainly Spain), but were born in the Americas.
And while most Spanish controlled regions in South America rebelled and sought independence, the conservative aristocracy of the Viceroyalty of Peru stayed loyal to the Spanish Crown making the Viceroyalty of Peru the last stronghold of Spanish domination in South America. So, Peru’s independence didn’t emerge from within the country, the driving and executing force were primarily outsiders.
One of them was José de San Martín, an Argentine General and the prime leader of the independence movement in the southern and central parts of South America. His goal was to destroy the remaining power of the Spaniards in South America, ensuring Argentine independence and control over the rich silver deposits in Upper Peru (today’s Bolivia). As Argentine forces had been defeated in Upper Peru before, San Martín first set out to liberate Chile, which he successfully did in 1818 and then used it as a base to attack Peru. In 1819 he disembarked in Paracas leading a military campaign to liberate Peru and with this whole South America from Spanish rule. At the end of 1820, San Martín’s army defeated the Spanish forces in the battle of Pisco and occupied the important Peruvian port. The Viceroy withdrew his forces into the interior, paving the way for San Martín and his forces to enter the capital Lima without large resistance.
Declaration of Independence July 28, 1821
On July 28, 1821, José de San Martín officially declared Peru's independence from Spain at the Plaza de Armas in Lima with the words: “From this moment on, Peru is free and independent, by the general will of the people and the justice of its cause that God defends. Long live the homeland! Long live freedom! Long live our independence!"
However, the declaration of independence didn’t liberate Peru from Spain. Resistance of the royalists and strong Spanish forces in the interior of the country led to three chaotic and martial years. After Simón Bolívar, a Venezuelan military and freedom fighter, came to San Martín’s help, differences between the two over the political fate of Peru - San Martín wanted Peru to become a constitutional monarchy while Bolivar preferred a republic - resulted in San Martín withdrawing from Peru in September 1822 and leaving Bolivar to carry on the struggle for complete independence. While the Peruvian coast, including the capital Lima and Northern Peru, was under the control of the Republic, the rest of the country was under command of the royalists who had established their new capital in Cusco. This time of war left Peru suffering from the disruption of the all-important trade and the forced contributions imposed by both sides.
In February 1824, the Congress of Republican Peru named Simon Bolivar dictator of Peru giving him the power to completely reorganize the political and military administration. And finally, at the Battle of Junín (August 1824) and the Battle of Ayacucho (December 1824) led by Venezuelan General Antonio José de Sucre, the Spanish power in the interior of the country was broken and the Spanish troops defeated ending the Spanish reign in South America and bringing political independence. However, the fighting wouldn’t end completely until the last royalists surrendered the Real Felipe Fortress (1826), the Huanta Rebellion was quelled (1828), Spanish attempts to regain power, such as the Battle of Callao (1866), were parried, and the Spanish finally recognized the Independence of Peru in 1879.