First Treaty of San Ildefonso

The First Treaty of San Ildefonso was signed on 1 October 1777 between Spain and Portugal. It settled long-running territorial disputes between the two kingdoms' possessions in South America, primarily in the Río de la Plata region.
Background.
For nearly 300 years, differing interpretations of the Treaty of Tordesillas led to border disputes between Spain and Portugal over the Río de la Plata region. Although Spanish silver mines in Potosí were far to the west of the disputed area, Portugal constantly tried to annex the silver lode region to its Brazilian colonies.
The two countries attempted to resolve their issues in the 1750 Treaty of Madrid but in 1761, it was annulled by the new Spanish monarch Charles III. In 1762, Spain entered the Seven Years' War on the side of France, resulting in the so-called Fantastic War of 1762-1763.
With British support, the Portuguese repulsed a Franco-Spanish invasion in Europe. In South America, Spain captured the Portuguese port of Colonia del Sacramento, now in Uruguay and much of the modern day Brazilian state of Rio Grande do Sul. However, the 1763 Treaty of Paris required Spain to return Colonia del Sacramento and by 1777, Portugal had reoccupied Rio Grande do Sul. 
Much of Spanish South America was controlled by the Viceroyalty of Peru which required all trade to pass through Lima on the Pacific. This policy made imports expensive, prevented the economic development of the Atlantic coast and caused increasing dissatisfaction with Spanish rule. Portuguese encroachments in the Río de la Plata allowed their merchants to evade these commercial restrictions; Buenos Aires subsequently become a major center for smuggled goods. In an attempt to regain economic and political control, a new Viceroyalty of the Rio de la Plata was established in 1776, with its capital at Buenos Aires. Despite opposition from Lima, limited free trade was permitted between Buenos Aires, Montevideo and mainland Spain.
Between 1775 and 1776, the undeclared war in the region between the two countries grew increasingly bitter, although the Spanish–Portuguese War only formally began in 1776. In February 1777, the new Viceroy of Río de la Plata, Pedro Antonio de Cevallos took command of a Spanish expeditionary force of 116 ships and 19,000 troops. He captured the island of Santa Catarina in February before moving against Colonia del Sacramento which surrendered in July.
In August, Cevallos learned Joseph I of Portugal had died in February; his daughter, Maria I now sued for peace and offensive operations ceased.
Provisions.
Under the Treaty, Portugal ceded Colonia del Sacramento, the associated island of San Gabriel and the Misiones Orientales while Spain acknowledged Portuguese control of Southern Brazil and returned Santa Catarina island. A Boundary Commission was established to delineate colonial borders between the Portuguese and Spanish Empires, which were later confirmed by the 1778 Treaty of El Pardo Portugal agreed to prevent the smuggling of goods and deny use of its ports to military or commercial vessels from nations hostile to Spain. This was aimed at Britain, with whom Spain was at war from 1779 to 1783.
Aftermath.
Charles hoped settling the border would help the economic growth of the new Viceroyalty and reduce unrest among its population. While partially successful, development was hampered by the 1779-1783 war with Britain that restricted trade with mainland Spain and led to high tariffs and taxes to pay for it. The smuggling of duty-free goods remained a lucrative occupation, while heavy taxes and 'voluntary' donations caused unrest, such as the 1781 Revolt of the Comuneros in the Viceroyalty of New Granada.
Portugal regained the Misiones Orientales in the Treaty of Badajoz (1801). Spanish participation in the Napoleonic Wars and the loss of much of its navy at the Battle of Trafalgar in 1805 severed links between the central government and its restive colonies in the Americas. British assaults on Buenos Aires and Montevideo in 1806 and 1807 were repulsed by locally led forces, which gave them the confidence to demand self-rule. The Viceroyalty of Río de la Plata was dissolved during the 1810-1818 Argentine War of Independence.
The Misiones Orientales were the location of the Jesuit-mission to the Guarani people and the basis for the 1986 Robert De Niro film "The Mission".