During the European Peninsular War of 1807 to 1814, the Spanish Empire began to lose control of its foreign colonies. Napoleon and France had created a crisis for the Spanish; protecting domestic borders was paramount for Spain, which meant a temporary lapse in colonial control. For Spain’s American colonies, this was an opportunity to wrest control from the royalists and push for independence.
In 1813, two of America’s greatest liberators, José de San Martín and Simón Bolívar, were at opposite ends of the South American continent. San Martín was in Argentina, leading the patriots against the royalist forces. Bolívar, meanwhile, was in Venezuela, heading the struggle for independence in the north. The two generals began to take control of their respective territories, claiming independence from Spain.
By the start of the 1820s, the two liberators were converging on Peru. Peru, and particularly Lima, was a stronghold for royalists and one of the last Spanish-ruled territories in South America to declare its independence (Upper Peru, now known as Bolivia, gained its independence a few years after Peru).
Despite royalist opposition, José de San Martín occupied Lima in July 12, 1821. In front of a massed crowd in Lima’s Plaza de Armas, San Martín proclaimed Peru’s independence on July 28, 1821. The royalists were not defeated, however, and the newly independent nation still had to deal with notable pockets of Spanish resistance.
The final act of the war of independence, for both Peru and South America, took place at the Battle of Ayacucho in 1824. Antonio José de Sucre, one of Bolívar's finest lieutenants, led a combined force, including Peruvians, Chileans, Colombians and Argentines, against the royalist army. Sucre won the day on the high plateau outside Ayacucho, securing a lasting independence for Peru and all but ending the Spanish American wars of independence.