Accession
When Philip II of Portugal (III of Spain) died, he was succeeded by his son Philip III (IV of Spain), who had a different approach to Portuguese issues. Taxes on the Portuguese merchants were raised, the Portuguese nobility began to lose its influence, and government posts in Portugal were increasingly occupied by Spaniards. Ultimately, Philip III tried to make Portugal a Spanish province, meaning Portuguese nobles stood to lose all of their power.
This situation culminated in a revolution organised by the nobility and the bourgeoisie, executed on 1 December 1640, sixty years after the accession of Philip II of Spain to the throne of Portugal. A plot was planned by several associates, known as the Forty Conspirators, who killed the Secretary of State, Miguel de Vasconcelos, and imprisoned the king's cousin, Margaret of Savoy, the Vicereine of Portugal, governing the country in the King's name. Philip III's troops were at the time fighting the Thirty Years' War and also dealing with a revolution in Catalonia, which severely hampered Spain's ability to quash the rebellion.
Within a matter of hours and with popular support, John, then the 8th Duke of Braganza, was acclaimed as King John IV of Portugal (as the legend goes, with the persuasion of his wife), claiming legitimate succession through his grandmother Catherine, Duchess of Braganza. The ensuing conflict with Spain brought Portugal into the Thirty Years' War as, at least, a peripheral player. From 1641 to 1668, the period during which the two nations were at war, Spain sought to isolate Portugal militarily and diplomatically, and Portugal tried to find the resources to maintain its independence through political alliances and maintenance of its colonial income.