The history of the Kingdom of Portugal and the Algarves, from the First Treaty of San Ildefonso and the beginning of the reign of Queen Maria I in 1777, to the end of the Liberal Wars in 1834, spans a complex historical period in which several important political and military events led to the end of the absolutist regime and to the installation of a constitutional monarchy in the country.

In 1807, Napoleon ordered the invasion of Portugal and subsequently the royal family and its entire court migrated to Brazil, Maria I declaring the United Kingdom of Portugal, Brazil and the Algarves in 1815. This would be one of the causes for the declaration of Brazilian independence by Pedro I of Brazil in 1822, following a liberal revolution in Portugal.

The liberal period was stormy and short as Miguel of Portugal (Pedro's brother) supported an absolutist revolution endeavoring to restore all power to the monarchy. Pedro eventually returned to Portugal and fought and defeated his brother in the Liberal Wars in which liberalism prevailed and Portugal became a constitutional monarchy.

Queen Maria I

The death of King Joseph in 1777 forced the accession of Princess Maria Francisca, his eldest daughter, to the throne of Portugal; she succeeded her father as the first Queen regnant of the 650-year-old country, which was still recovering from the 1755 Lisbon earthquake. Before becoming queen, Princess Maria and her husband, the Infante Pedro, lived on the sidelines of politics, but were clearly unsympathetic to her father's former Prime Minister, Sebastião José de Carvalho e Melo, the Marquis of Pombal, who had been the de facto ruler of the kingdom for the past 27 years.José Hermano Saraiva, (2007), p.260Marcus Cheke (1969), p.3 During her father's last few years, she had been the Marquis' fiercest detractor; once in power, she eagerly dismissed him and then exiled him to Pombal.Her dislike for Pombal was so great that she issued one of the world's earliest restraining orders, commanding that Pombal should never be closer than to her; in situations where the Queen was close to his estates, he was compelled to remove himself from his house to fulfill the royal decree. She is also reported to have had tantrums at the slightest reference to her father's former Prime Minister.

Although the queen retained many of the Marquis' other ministers, she restored most of the privileges of the nobility and clergy, and released many of Pombal's political prisoners.José Hermano Saraiva, (2007), p.260-261 The economy was reorganized and Pombaline monopolies were abandoned. However, international conditions favored the economic situation in Portugal as the balance of trade was positive, helped by wine exports and a decrease of British imports.José Hermano Saraiva, (2007), p.261 The period was, while tainted by political instability, a time of cultural renovation, marked by the completion of the Palace at Queluz, the beginnings of the Ajuda Palace, the São Carlos Theatre, the Estrela Basilica and the immense Convent of Santa Clara in Vila do Conde.José Hermano Saraiva, (2007), p.262-263

In 1789, the French Revolution caused great social upheaval in Europe. The eventual Portuguese reaction was to land forces in Catalonia, and together with the Spanish forces attack the French in the Pyrenees in the War of Roussillon (1794).José Hermano Saraiva, (2007), p.263 The war did not go well, and by 1795, Spain had privately sued for peace, signed an alliance and aligned its external politics against Great Britain.José Hermano Saraiva, (2007), p.264 Even as Portugal was politically divided between continuing its old alliance with Britain, its people were also divided. The French Revolution, as seen by intellectuals and progressives, was romanticized: Bocage and the Partido Francês (French Party) believed the French could usher in a liberal revolution in Europe. The French represented a threat to the traditionalist nobility who were returning to prominence and were very willing to fight them externally or internally.

It was at about this time that Queen Maria, already possessed of a religious mania, began to show signs of mental illness.José Hermano Saraiva, (2007), p.265 When after 1799 she became incapable of handling state affairs, her son, Infante John of Braganza, began to use the title of Prince-Regent. The traditionalist adversaries of France, however, did not look to John, but rather to his wife Carlota Joaquina for support, and at one point attempted a coup against the prince.

Continental blockade John VI's regency was a complex political period that saw Portugal attempting to remain neutral in spite of the combative intransigence of its neighbors and contentious forces within the country that favored either liberal or traditional policies. Between 1795 and 1801, his government struggled to maintain a delicate balance of peace in the face of the French Continental blockade against Portugal's traditional ally, Great Britain, and the demands of the merchant classes who were prospering economically and wanted peace. Meanwhile, Spain, a former ally, had signed the Second Treaty of San Ildefonso, and was under pressure from France to coerce Portugal's cooperation, even if it required an invasion. Although Manuel de Godoy was initially hesitant to invade Portugal, due to the royal family having relatives in both countries, the French remained anxious to break the Anglo-Portuguese alliance in order to close Portuguese ports to British shipping.CUP (1970), p.386-389

War of the Oranges

On 29 January 1801, an ultimatum from Spain and France forced Portugal to decide between France and Britain, even as its government had tried to negotiate favorable relations with the two powers rather than abrogate the Treaty of Windsor (1386). The French sent a five-point statement to Lisbon demanding that Portugal:H.V.Livermore (1976), p.247 abandon its traditional alliance with the United Kingdom and close its ports to British shipping; open its ports to French and Spanish shipping; surrender one or more of its provinces, equal to one fourth part of her total area, as a guarantee for the recovery of Trinidad, Port Mahon (Menorca) and Malta; pay a war indemnity to France and Spain; review border limits with Spain. If Portugal failed to accomplish the five conditions of this ultimatum, it would be invaded by Spain, supported by French soldiers. The British could not promise any effective relief, even as Prince John appealed to Hookham Frere, who arrived in November 1800. In February, the terms were delivered to the Prince-Regent; although he sent a negotiator to Madrid, war was declared. At the time, Portugal had a poorly trained army, with less than 8000 cavalry and infantry troops. Its military commander, João Carlos de Bragança e Ligne (2nd Duke of Lafões), had barely raised 2000 horse and troops.H.V. Livermore (1976), p.247 and was compelled to contract the services of a Prussian colonel, Count Karl Alexander von der Goltz, to assume command as field marshal. The Spanish Prime Minister and Commander-in-Chief, Manuel de Godoy, had some troops at his disposal, while the French troops under General Charles Leclerc (Napoleon's brother-in-law) arrived in Spain too late to assist Godoy, as it was a short military campaign.

On May 20, Godoy finally entered Portugal; this incursion was a precursor of the Peninsular War that would engulf the Iberian Peninsula. The Spanish army quickly penetrated the Alentejo region in southern Portugal and occupied Olivença, Juromenha, Arronches, Portalegre, Castelo de Vide, Barbacena and Ouguela without resistance. Campo Maior resisted for 18 days before falling to the Spanish army, but Elvas successfully resisted a siege by the invaders. An episode which occurred during the siege of Elvas accounts for the name, "War of the Oranges": Godoy, celebrating his first experience of generalship, plucked two oranges from a tree and immediately sent them to Queen Maria Luisa of Spain, mother of Carlota Joaquina and supposedly his lover, with the message:

The conflict ended quickly when the defeated and demoralized Portuguese were forced to negotiate and accept the stipulations of the Treaty of Badajoz, signed on June 6, 1801. As part of the peace settlement, Portugal recovered all of the strongholds previously conquered by the Spanish, with the exception of Olivença and other territories on the eastern margin of the Guadiana, and a prohibition of contraband was enforced near the border between the two countries. The treaty was ratified by the Prince-Regent on 14 June, while the King of Spain promulgated the treaty on 21 June.

A special convention (i.e., the Treaty of Madrid) on 29 September 1801 made additions to that of Badajoz whereby Portugal was forced to pay France an indemnity of 20 million francs. This treaty was initially rejected by Napoleon, who wanted the partition of Portugal, but accepted once he concluded a peace with the United Kingdom at Amiens.H.V.Livermore (1976), p.248

Napoleonic invasions

In 1806, after Napoleon's victory over the Prussians, he considered the problem of the resistance of the English, who had broken the peace in 1803 to challenge the Continental System imposed by the French, and realized that the situation in Portugal impeded his plan for reform in Europe.José Hermano Saraiva, (2007), p.266 Again, Portuguese ports were ordered closed to British shipping;

On 27 October 1807, France and Spain signed the Treaty of Fontainebleau which would partition Portugal. In this pact, Northern Lusitania, a territory between the Minho and Douro rivers, would be a principality governed by the sovereign of the extinct Kingdom of Etruria (then Maria Luisa, daughter of Charles IV of Spain). The Algarve and all Portuguese territory located south of the Tagus would be governed by Manuel de Godoy, in compensation for his role in bringing the Spanish to align with France. The rest of Portugal, the area between the Douro and the Tagus, a strategic region because of its ports, would be administered by the central government in France until a general peace. Its colonial possessions, including Brazil, would be divided between Spain and France.

On either 19 or 20 November 1807, a French battalion commanded by General Jean-Andoche Junot entered Portugal. Napoleon had ordered its invasion and occupation.

On 27 November, the Prince Regent, the Queen and the entire royal family, accompanied by much of the nobility as well as their servants, boarded fifteen Portuguese ships gathered in the Tagus with an escort of several English ships,CUP (1970), p.396 as planned the year before when the British ambassador advised the prince that the Portuguese Crown should be transferred to Brazil. Approximately people, including the entire governmental administration and the judiciary, joined the royal family as they moved to Brazil, a possession of Portugal, and established the capital of the Portuguese Empire in Rio de Janeiro.

First invasion