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.