The Viceroyalty of Peru (Spanish: Virreinato del Perú), officially known as the Kingdom of Peru (Spanish: Reino del Perú), was a Spanish imperial provincial administrative district, created in 1542, that originally contained modern-day Peru and most of the Spanish Empire in South America, governed from the capital of Lima. Along with the Viceroyalty of New Spain, Peru was one of two Spanish viceroyalties in the Americas from the sixteenth to the eighteenth centuries.
The Spanish did not resist the Portuguese expansion of Brazil across the meridian established by the Treaty of Tordesillas. The treaty was rendered meaningless between 1580 and 1640 while Spain controlled Portugal. The creation during the 18th century of the Viceroyalties of New Granada and Río de la Plata (at the expense of Peru's territory) reduced the importance of Lima and shifted the lucrative Andean trade to Buenos Aires, while the fall of the mining and textile production accelerated the progressive decay of the Viceroyalty of Peru. Eventually, the viceroyalty would dissolve, as with much of the Spanish Empire, when challenged by national independence movements at the beginning of the nineteenth century. These movements led to the formation of the modern-day country of Peru, as well as Chile, Colombia, Panama, Ecuador, Bolivia, Paraguay, Uruguay, and Argentina, the territories that at one point or another had constituted the Viceroyalty of Peru.