Lima, capital of the Viceroyalty of Peru, was the most important city of the Spanish colonies in South America. It was a royalist stronghold during the Spanish American wars of independence, fighting against the several independentist outbreaks. For this reason, after the conclusion of the Chilean War of Independence the general José de San Martín organized a navy that allowed his forces to siege and capture the city, declaring the independence of Peru shortly afterwards. However, there was still a strong royalist force in the Peruvian countryside.