structural:reformatting, structural:scholar_edition, information:highlighting
Struggle for independence

During the struggle for independence, before Peru or Ecuador became independent, areas of the former Vice Royalty of New Granada declared themselves independent from Spain. A few months later, a part of the Peruvian liberation army of San Martín decided to occupy the independent cities of Tumbez and Jaén, with the intention of using them as springboards to occupy the independent city of Guayaquil and then liberate the rest of the Audiencia de Quito (Ecuador). It was common knowledge among officers of the liberation army from the south that their leader San Martín wished to liberate present-day Ecuador and add it to the future republic of Peru, since it had been part of the Inca Empire before the Spaniards conquered it. However, Bolívar 's intention was to form a new republic known as the Gran Colombia, out of the liberated Spanish territory of New Granada which consisted of Colombia, Venezuela, and Ecuador. San Martín's plans were thwarted when Bolívar, descended from the Andes mountains and occupied Guayaquil; they also annexed the newly liberated Audiencia de Quito to the Republic of Gran Colombia.

In the south, Ecuador had claims to a small piece of land beside the Pacific Ocean known as Tumbes. In Ecuador's southern Andes Mountain region where the Marañon cuts across, Ecuador had claims to an area it called Jaén de Bracamoros. These areas were included as part of the territory of Gran Colombia by Bolivar on 17 December 1819, during the Congress of Angostura when the Republic of Gran Colombia was created. Tumbes declared itself independent from Spain on 17 January 1821, and Jaén de Bracamoros on 17 June 1821, without any outside help from revolutionary armies. However, that same year, Peruvian forces participating in the Trujillo revolution occupied both Jaén and Tumbes. Peruvian generals, without any legal titles backing them up and with Ecuador still federated with the Gran Colombia, had the desire to annex Ecuador to the Republic of Peru at the expense of the Gran Colombia, feeling that Ecuador was once part of the Inca Empire.

On 28 July 1821, Peruvian independence was proclaimed in Lima by San Martín, and Tumbes and Jaén, which were included as part of the revolution of Trujillo by the Peruvian occupying force, had the whole region swear allegiance to the new Peruvian flag and incorporated itself into Peru. Gran Colombia had always protested Peru for the return of Jaén and Tumbes for almost a decade, then finally Bolivar after long and futile discussion over the return of Jaén, Tumbes, and part of Mainas, declared war. President and General José de La Mar, who was born in Ecuador, believing his opportunity had come to annex the District of Ecuador to Peru, personally, with a Peruvian force, invaded and occupied Guayaquil and a few cities in the Loja region of southern Ecuador on 28 November 1828.

The war ended when an outnumbered southern Gran Colombian army at Battle of Tarqui on 27 February 1829, led by Antonio José de Sucre, defeated the Peruvian invasion force led by President La Mar. This defeat led to the signing of the Treaty of Guayaquil in September 1829, whereby Peru and its Congress recognized Gran Colombian rights over Tumbes, Jaén, and Maynas. Through meetings between Peru and Gran Colombia, the border was set as Tumbes river in the west, and in the east, the Maranon and Amazon rivers were to be followed toward Brazil as the most natural borders between them. According to the peace negotiations Peru agreed to return Guayaquil, Tumbez, and Jaén; despite this, Peru returned Guayaquil, but failed to return Tumbes and Jaén, alleging that it was not obligated to follow the agreements, since the Gran Colombia ceased to exist when it divided itself into three different nations – Ecuador, Colombia, and Venezuela.

The Central District of the Gran Colombia, known as Cundinamarca or New Granada (modern Colombia) with its capital in Bogota, did not recognize the separation of the Southern District of the Gran Colombia, with its capital in Quito, from the Gran Colombian federation on 13 May 1830. After Ecuador's separation, the Department of Cauca voluntarily decided to unite itself with Ecuador due to instability in the central government of Bogota. The Venezuelan born President of Ecuador, the general Juan José Flores, with the approval of the Ecuadorian congress annexed the Department of Cauca on 20 December 1830, since the government of Cauca had called for union with the District of the South as far back as April 1830. Moreover, the Cauca region, throughout its long history, had very strong economic and cultural ties with the people of Ecuador. Also, the Cauca region, which included such cities as Pasto, Popayán, and Buenaventura, had always been dependent on the Presidencia or Audiencia of Quito.

Fruitless negotiations continued between the governments of Bogotá and Quito, where the government of Bogotá did not recognize the separation of Ecuador or that of Cauca from the Gran Colombia until war broke out in May 1832. In five months, New Granada defeated Ecuador due to the fact that the majority of the Ecuadorian Armed Forces were composed of rebellious angry unpaid veterans from Venezuela and Colombia that did not want to fight against their fellow countrymen. Seeing that his officers were rebelling, mutinying, and changing sides, President Flores had no option but to reluctantly make peace with New Granada. The Treaty of Pasto of 1832 was signed by which the Department of Cauca was turned over to New Granada (modern Colombia), the government of Bogotá recognized Ecuador as an independent country and the border was to follow the Ley de División Territorial de la República de Colombia (Law of the Division of Territory of the Gran Colombia) passed on 25 June 1824. This law set the border at the river Carchi and the eastern border that stretched to Brazil at the Caquetá river. Later, Ecuador contended that the Republic of Colombia, while reorganizing its government, unlawfully made its eastern border provisional and that Colombia extended its claims south to the Napo River because it said that the Government of Popayán extended its control all the way to the Napo River.