The Colombian War of Independence was fought between Colombian patriots and Spanish royalists from 1810 to 1825, resulting in the independence of Gran Colombia, Peru, and Bolivia and the end of Spain's political presence in South America.
The Viceroyalty of New Granada had first rebelled against its Spanish rulers from March to October 1781 in the Revolt of the Comuneros, a response to new taxes levied to fund Spain's participation in the American Revolutionary War. The Spanish authorities also excluded locally born whites, the criollo caste, from public administration, generating continued resentment. In 1810, the accession of Napoleon I's brother Joseph Bonaparte to the throne of Spain amid the Peninsular War resulted in the formation of a Supreme Central Junta in Spain and local juntas in many of Spain's South American colonies. Though an attempt to establish a junta in neighboring Caracas was suppressed in 1808, juntas were formed in Charcas and La Paz in 1808-1809, as well as in Quito in 1808. After the Supreme Central Junta dissolved itself in favor of a regency in mid-1810, new boards of government were established in Caracas and Cartagena de Indias.
On 20 July 1810, Joaquin Camacho's request for Viceroy Antonio Jose Amar y Borbon to permit the establishment of a junta in the Neogranadine capital of Bogota was declined. At the same time, the refusal of a Spanish businessman to loan two criollos a vase to welcome royal commissioner Antonio Villavicencio was the spark that set off a criollo revolt. On 21 July, the Bogota junta deposed Amar y Borbon, and, on 26 July, the Bogota junta declared the independence of New Granada from Spanish rule. More provincial capitals would break their ties with Spain in the coming months.
However, the juntas across New Granada were unable to agree on how to work together. The country was divided between Federalists and Centralists, with the Federalists founding the First Republic of New Granada and the Centralists founding the Free and Independent State of Cundinamarca. The rival patriot governments fought each other during the "Foolish Fatherland" civil war of 1812-1814, while the north and south of the country remained under Royalist control. The Patriots' Magdalena Campaign cut off Cartagena from Colombia's interior, but it failed to capture the port of Santa Marta, and the Neogranadine general Antonio Nariño was defeated and captured at the Battle of Ejidos de Pasto in May 1814. At the same time, the Second Republic of Venezuela was destroyed by Royalists and their llanero allies, who rejected white supremacist Patriot rule.
In 1815, King Ferdinand VII of Spain dispatched 10,000 troops and 60 ships to South America, with Colonel Pablo Morillo being entrusted with reconquering South America's northern colonies. The Spanish took Cartagena after a 105-day siege and attacked the rest of the country on three fronts. The Patriots were defeated at the Battle of Cuchilla del Tambo in June 1816, and a lack of coordination between the provinces resulted in continued Patriot losses. Several Patriots were executed for treason, while others, like Francisco de Paula Santander, retreated to the eastern plains to reorganize political and military forces to face the new adversary.
In May 1819, after Simon Bolivar liberated Venezuela, his army crossed the Cordillera Oriental during the rainy season and surprised the Spanish forces in New Granada in July. At the Battle of Vargas Swamp on 25 July, Bolivar defeated a Royalist force attempting to reinforce the poorly-defended capital of Bogota, and the bulk of the Royalist army surrendered to him after the Battle of Boyaca in August 1819. Viceroy Juan de Samano and the rest of the Royalist government promptly fled to Cartagena de Indias and from there to Spain, and Bolivar entered Bogota on 10 August. On 17 December 1819, the Republic of Colombia - named for the explorer Christopher Columbus - was formally proclaimed.
On 25-26 November 1820, Bolivar and Morillo concluded a ceasefire, and the two generals held a meeting where, after great merriment, the two parted on friendly terms, Morillo leaving for Spain for good. The ceasefire fell through not long after, and the Patriots captured Cartagena in October 1821 after a 15-month siege. From 1822 to 1824, Bolivar and Antonio Jose de Sucre moved south to liberate southern Colombia and Ecuador in the Pasto Campaign. Pasto was the last remaining Royalist stronghold capable of stopping the southern expansion of the Revolution, and, after defeating the Venezuelan royalists at the Battle of Carabobo in August 1821, Bolivar advanced overland towards Quito in January 1822. Both sides suffered heavy losses at the Battle of Bombona in April 1822, but the Royalists were forced to retreat to Pasto after the Battle of El Peñol. On 24 May 1822, Sucre defeated the Royalists at the Battle of Pichincha, leading to the liberation of Quito and the capitulation of the Spanish colonial elite. On 8 June 1822, Bolivar triumphantly entered Pasto, enabling him to concentrate on Peru. The indigenous popular mass in southern Colombia refused to accept capitulation, and Jose Boves' nephew Benito Remigio Boves led a rebellion in Pasto in September 1822. Sucre's army killed 400 civilians during the Navidad Negra in Pasto on 23-25 December 1822, and all Royalist prisoners were shot. A new rebellion broke out under Agustin Agualongo in 1823, retaking Pasto in June. Bolivar defeated the rebels at the Second Battle of Ibarra on 17 June, and Agualongo failed to take Barbacoas in June 1824. He was captured on 24 June and executed in Popayan on 13 July 1824. On 9 December 1824, the Royalist defeat at the Battle of Ayacucho in Peru secured the independence of Spanish South America, including Gran Colombia.