Relations between Spain and Portugal are peaceful for most of the 16th century. Each has its own half of the world to exploit, with the dividing line of Tordesillas accepted on both sides. A similar division in the Pacific is agreed at Saragossa in 1529, in the aftermath of Magellan's voyage; it cedes the Moluccas to Portugal but leaves the Philippines open to Spain.

The energies of tiny Portugal are fully absorbed in this great task. Manuel I, coming to the throne in 1495, adopts a grandiloquent title to reflect his new responsibilities - 'lord of the conquest, navigation and commerce of India, Ethiopia, Arabia and Persia'.

By contrast mighty Spain has more pressing and varied responsibilities. Under the Holy Roman emperor Charles V, from 1519, Spain is involved in a complex web of European commitments as well as needing to give attention to its overseas empire.

It therefore suits both neighbours in the Iberian peninsula to remain on friendly terms. These are reflected in marital alliances. Manuel I of Portugal marries three successive wives from the Spanish royal family. His son John III, ruling Portugal from 1521 to 1537, is doubly a brother-in-law of Charles V. In 1525 he marries Charles's sister Catherine; in the same year Charles marries John's sister Isabella.

The situation changes dramatically in 1578 when John III's grandson, Sebastian, is killed in a disastrous attempt to lead a crusade against the Muslims of Morocco. The Christian army is demolished in an engagement at Alcazarquivir. Sebastian is followed on the Portuguese throne by his uncle, an elderly cardinal. On the cardinal's death two years later, only one member of the Portguese royal house is alive. She is Catherine, duchess of Braganza, niece of John III.

The king of Spain, Philip II, disregards her. He has claims of his own (his mother was John III's sister Isabella, his first wife was John III's daughter). A Spanish army marches into Portugal.

Philip II is accepted by the Cortes in 1581 (as Philip I of Portugal). He promises to preserve Portuguese autonomy, merging the crowns rather than the kingdoms - as has previously happened with Castile and Aragon, and will soon occur with Scotland and England. And he will appoint only Portuguese to the administration.

He keeps his word on these issues, but his son and grandson are less tactful. They treat their second kingdom of Portugal as a Spanish province. As a result it remains only sixty years in Spanish hands, until the Portuguese royal family is restored as the house of Braganza.

House of Braganza: 1640-1777

Portuguese resentment of Spanish rule increases during the 1630s and is eagerly stirred up by secret agents in Lisbon working for Cardinal Richelieu. In 1640 an almost bloodless revolution sweeps out the Spanish and brings to the throne, as John IV, the duke of Braganza - grandson of Catherine, the rightful heir sixty years previously.

The return of the Portuguese royal line renews the ancient alliance with England. In 1662 the English king Charles II marries John's daughter, Catherine of Braganza. She brings a large dowry, including Bombay. In return England supports Portugal against Spain's continuing hostility, until Spain finally accepts Portuguese independence in 1668.

It is impossible for Portugal to avoid being drawn into two European wars - the War of the Spanish Succession, and the Seven Years' War - but the 18th century is a time of prosperity. This partly derives from the wealth now flowing from Brazil, where gold is found in large quantities in 1693 and diamonds in 1728.

English influence in the country continues to grow, particularly after the Methuen Treaty of 1703 provides advantageous terms for trade. Portugal agrees to import all her woollen goods from Britain. England puts less import duty on Portuguese wines than on French - beginning the English tradition of drinking fortified Portuguese red wine as 'port'.

In 1755 Lisbon suffers a disastrous earthquake. The man who rebuilds the city, with ruthless efficiency, is rewarded with the post of chief minister and a new title as the marquis of Pombal. In the remaining twenty years of the reign of Joseph (king from 1750 to 1777) Pombal reforms Portugal, often with considerable brutality, in keeping with the contemporary fashion for enlightened despotism. And he takes an equally strong line with Portugal's most productive colony, Brazil.

Pombal's career ends with the reign. Joseph's daughter, Maria I, frees Portugal's political prisoners and has Pombal investigated for abuse of his powers. Found guilty, he is exiled from Lisbon.

Maria I: 1777-1816

After a forceful beginning to her reign, Maria suffers a series of debilitating blows. The death of her husband in 1786 (he is given the title Pedro III as her consort) is followed in 1788 by that of her eldest son. These tragedies cast the queen into a severe depression.

The following year brings the start of the French Revolution. As successive indignities are heaped upon the royal family in France, Maria's mental condition worsens. In 1792, even before the execution of Louis XVI, she is judged unfit to fulfil her duties. Her eldest surviving son, the future John VI, rules at first in her name and then becomes, in 1799, the official prince regent.

In 1793 Portugal joins the alliance of Europe's monarchies in declaring war against the regicide French republic. But whereas several of the combatants lapse into neutrality or even change sides by 1796, Portugal holds true to the cause of her long-standing ally, England.

After the peace of Amiens, in 1802-3, Portugal attempts to maintain a stance closer to neutrality. But this soon becomes unacceptable to Napoleon, increasingly desperate to complete his Continental System and thus deny Britain access to any European port. The result is his impulsive move of 1807, which sends Maria and her regent son into exile and turns Portugal into a theatre of war.

Spain and Portugal: 1807-1809

In October 1807 Napoleon decides that the only certain method of securing the Continental System is a French occupation of Portugal. He despatches an army for the purpose and summons Spanish envoys to Fontainebleau.

In a treaty signed at Fontainebleau, on October 27, the partition of Portugal is agreed. France is to have the central section, including Lisbon and Oporto. The Algarve in the south will go to Godoy, the Spanish king's unscrupulous chief minister. The north will be granted to the young duke of Parma in return for his valuable kingdom of Etruria (or in plain terms Tuscany), which will be ceded to France.

Even before the treaty is signed a French army has entered Spain on its way to Portugal - where its imminent arrival near Lisbon causes panic. The royal family and court decide to flee for safety to Brazil, taking with them (to Napoleon's fury) the gold and silver of the national treasure. A Portuguese fleet, accompanied by a British squadron, sails from the mouth of the Tagus on 29 November 1807. The vanguard of the French army enters the capital city the next day.

It will be fourteen years before the return to Lisbon of a Portuguese monarch. But the French are to have only a very short tenure. Their intrusion launches the Peninsular War. Before a year is out, the British are in the city.

A British army lands in Portugal on 1 August 1808 under the command of Wellington (at the time plain Sir Arthur Wellesley), who wins a decisive victory over the French at Vimeiro, near Lisbon. Wellington is prevented from pursuing and further damaging the French army on the command of Hew Dalrymple, an officer senior to him who arrives just after the battle to take charge of the campaign.

By an agreement made at Sintra on August 31, Dalrymple allows the French army to withdraw from Portugal. The advantage is that the British can liberate Lisbon without further conflict. But an affronted Wellington returns home to resume a career in British politics.

Meanwhile Spanish forces are engaging the French in northern Spain. In October John Moore, newly in command of the British army in Portugal, marches north to assist them. The French situation in Spain appears so critical that Napoleon himself arrives (on November 6) to take charge of the campaign.

By late December Moore's army, near Burgos, is in danger of being surrounded. Moore beats a hasty retreat of some 250 miles through snowclad mountains to Corunna (or La CoruÑa). A French army arrives there shortly before the British fleet sent to evacuate the troops. Moore himself dies in January 1809 in the rearguard action to cover the embarkation, but his army escapes safely back to England.

Wellington in the ascendant: 1809-1814

In spite of the reverse suffered at Corunna, the British government undertakes a new campaign in Portugal. Wellington, who has won the only victory there so far, is returned to his command. He reaches Lisbon in April 1809 to find that the French have again pressed south into Portugal, against dwindling Portuguese and Spanish opposition, and have captured Oporto.

Wellington's campaign of 1809 includes successful sorties northwards in Portugal and an ambitious march to the east against Madrid. This ends with a hard fought battle on July 27 at Talavera, where Wellington holds off strong French assaults and is able to withdraw, relatively undamaged, to Portugal.

It is clear that the British position in the peninsula is tenuous. Wellington's response to this fact is the most imaginative strategic move of the Peninsular War. He turns the region north of Lisbon into a gigantic fortress by building the lines of Torres Vedras - a continuous fortification stretching twenty-five miles from the Atlantic coast through Torres Vedras to the broad Tagus river.

With British naval power protecting the port of Lisbon, there is now a large territory behind these impenetrable lines in which Wellington's army has a secure base in which it can be reliably supplied from the sea.

Campaigns in subsequent years involve prolonged fighting over the fortified towns between Portugal and Madrid; both Ciudad Rodrigo and Badajoz are eventually taken by Wellington in 1812. Later in that year he wins a significant victory at Salamanca and briefly occupies Madrid.

The decisive campaign comes in 1813, when Wellington moves north from Portugal and meets the army of Napoleon's brother Joseph Bonaparte (technically at this stage king of Spain) at Vitoria on June 21. Wellington captures the entire French artillery train, of some 150 guns, and all the baggage - including Joseph's impressive collection of art, which now graces Apsley House (Wellington's residence in London).

Liberals and absolutists: 1820-1831

With the end of the Peninsular War, and the defeat of Napoleon in 1814, Portugal enters a brief period of political hiatus. The royal family is in exile in Brazil. As a result of the six years of war, British officers are carrying out many of the functions of everyday administration.

This uneasy state of affairs comes to a sudden end in August 1820 when liberals in Oporto, following the example of colleagues in Spain earlier in the year, launch an uprising to demand a proper constitution for the nation. Their cause spreads rapidly through the country.

In October all British officers are expelled from Portugal. In January 1821 the Cortes assembles in Lisbon and prepares a constitution, abolishing the remains of feudalism, ending the role of the Inquisition in Portugal, and limiting the powers of the king in relation to an elected assembly.

The absent monarch, John VI, is therefore presented with a fait accompli - and one which makes advisable his hurried return from Brazil. He arrives in Lisbon in July 1821 with his wife Carlota Joaquina and their second son, Dom Miguel. The king swears allegiance in 1822 to the new constitution, but his wife and son refuse to do so.

With this refusal Miguel, at the head of a faction insisting on the absolute power of the monarch, launches a family conflict which lasts for several years. In April 1824 Miguel leads an insurrection. It briefly topples his father, but with British help John VI recovers his throne. Miguel escapes to Vienna. A constitutional monarchy seems at this stage to have been safely established, but the conflict re-ignites when John VI dies in 1826.

John's eldest surviving son, now the emperor Pedro I of Brazil, inherits the Portuguese throne. He has no intention of returning to occupy it in person. Instead he proposes a somewhat impractical compromise.

Pedro relinquishes his throne in Portugal in favour of his 7-year-old daughter, Maria, on condition that her uncle Miguel marries her and accepts a liberal charter - which Pedro now promulgates in place of the constitution of 1820.

Dom Miguel, in exile in Vienna, sees his chance. He accepts the terms, swears allegiance to his brother, and arrives in Lisbon as regent in February 1828. Once in power, Miguel immediately goes back on his oath. With the support of the absolutist faction, he is proclaimed king and begins a vigorous persecution of his liberal opponents. This sequence of events is broadly welcome in a backward and profoundly Catholic Portugal, where an absolute monarch seems very much more reassuring than a liberal.

The War of the Two Brothers: 1829-1834

By the end of 1828 Miguel is undeniably the de facto king of Portugal, and is recognized as such by several foreign powers (including the Holy See, Spain and Russia). The liberal leaders and the royal child, Maria, flee to exile in Britain. The whole of Portugal seems content with the new dispensation, apart from one tiny corner. On Terceira, one of the islands of the Azores, the garrison remains loyal to Pedro and Maria.

From this distant outpost, a campaign is launched. A regency is set up here on behalf of Maria. Her father Dom Pedro, after abdicating in Brazil, arrives in the Azores in February 1832 with a fleet and an army, composed mainly of British and French troops.

Dom Pedro's force reaches Portugal in July 1832 and succeeds in capturing the town of Oporto. Here they are besieged for a year, until a fleet of five British steamers arrives in the summer of 1833 with a reinforcement of mercenaries. In a battle in July, off Cape St Vincent, Miguel's fleet is destroyed. Later in the month Lisbon is taken.

After a series of battles during the winter of 1833-4, Miguel's armies are finally defeated. Dom Miguel, the absolutist king, surrenders in May and goes again into exile. Dom Pedro, the ex-emperor, dies before the end of the year (he is thirty-six). The war between the brothers is over. And Maria II (now fifteen) is undeniably queen.