By 1640, the Habsburg king, Philip IV of Spain, could no longer count on the trust, support or loyalty of most Portuguese nobles. The country was overtaxed, and Portuguese colonies had been left unprotected. Portugal, like many of Philip's domains, was on the verge of open rebellion. After 60 years of living under the rule of Spanish kings, a small band of conspirators in Lisbon rebelled and the Duke of Braganza was acclaimed King of Portugal as John IV on 1 December 1640, taking advantage of a simultaneous revolt in Catalonia and Spain's ongoing conflict with France. Thus began the 28-year Portuguese Restoration War. At first, Portugal lost many of its colonial possessions to the opportunistic Dutch. Portugal's military strength was reserved for protecting its own frontiers against Spanish incursions, but after 1648, the end of the Thirty Years' War allowed the reversal of those misfortunes. Portugal regained its colonies in Angola, São Tomé and Brazil by 1654. In 1652, Catalonia's rebellion against Spain collapsed, and in 1659, Spain ended its war with France and so there were grounds for Spanish optimism in the struggle to regain control over Portugal. However, Portugal could draw on the wealth of Brazil and the aid of first France and then England, but Spain's finances were perpetually in crisis. A series of successes by the Portuguese, with the help of a British brigade, made it clear that the Iberian Peninsula would not be reunited under Spanish rule. The first took place on 8 June 1663, when the count of Vila Flor, Sancho Manoel de Vilhena, with Marshal Schomberg by his side, utterly defeated John of Austria the Younger, an illegitimate son of Philip IV, at the Battle of Ameixial, before he retook Évora, which had been captured earlier that year. One year later, on 7 July 1664, Pedro Jacques de Magalhães, a local military leader, defeated the Duke of Osuna at Ciudad Rodrigo in the Salamanca Province of Spain. Finally, on 17 June 1665, the marquis of Marialva and Schomberg destroyed a Spanish army, under the Marquis of Caracena at the Battle of Montes Claros, followed by defeat at Vila Viçosa. The Spanish failed to gain any compensating advantage. A year later, desperate to reduce its military commitments at almost any price, Spain accepted the loss of the Crown of Portugal. A treaty was signed between England and Spain at Madrid in 1667. As a result, England mediated the Treaty of Lisbon, which recognised the sovereignty of the House of Braganza.
Portuguese sovereignty over its colonial possessions was reconfirmed except for the African exclave of Ceuta, a city that did not recognize the House of Braganza as the new ruling dynasty.
Agreements on the exchange of prisoners, reparations and the restoration of commercial relations were reached.
Portugal ceded Ceuta to Spain. Seven years earlier, the nearby city of Tangiers had been awarded to King Charles II of England, as part of the dowry of Catherine of Braganza, as was stipulated in the Treaty of Lisbon of 1661.
Consequences
The treaty had advantages for both countries. Spain, relieved to be ending a financially ruinous war, was quite pliant in the negotiations. Also, Portugal could now pursue the possession of its overseas colonies.
Aftermath
After 1668, Portugal, determined to differentiate itself from Spain, turned to Western Europe, particularly France and England, for new ideas and skills. That was part of a gradual "de-Iberianization", as Portugal consolidated its cultural and political independence from Spain. Portuguese nationalism, which was aroused by success on the battlefield, produced hostile reactions to Spanish things and persons. By then, Portuguese society was composed of two basic elements: those who participated in the gradual Europeanization process, the "political nation", and those who remained largely unchanged, the majority of the people, who remained apolitical and passive. Portugal's restoration of independence freed it to pursue the course mapped out by the pioneers of commercial imperialism. During the 17th century, its economy depended largely upon entrepôt trade in tobacco and sugar and the export of salt. During the 18th century, even though staples were not abandoned, the Portuguese economy came to be based more upon slaves, gold, leather and wine. Portuguese trade, centted in the busy port of Lisbon, was influenced especially by Anglo-Dutch capitalism and by the colonial economy in Brazil.