This article provides an analysis of royalist strategy in the viceroyalty of Peru during the four years between the arrival of José de San Martín's invasion force in September 1820 and the battle of Ayacucho of December 1824. It pays particular attention to royalist policy from July 1821, when viceroy José de la Serna evacuated Lima, the viceregal capital, leaving the city open to San Martín, who declared independence there on 28 July. Its focus differs, therefore, from that of most previous commentators on Peru's transition to independence, who have tended to neglect royalist policy and activity during these crucial final years in favour of a concentration upon the activities of San Martín, Antonio José de Sucre, Simón Bolívar and their Peruvian allies. The article begins with a brief contextual discussion of the historiography of Peruvian independence and subsequently analyses the main features of historical developments in the viceroyalty in the period 1810–20. Following substantive discussion of the period 1820–4, it concludes with observations on the historical legacy in Peru of the royalists' elevation of the city of Cusco to the status of viceregal capital in 1822–4.