Answer
The Portuguese Restoration War, which lasted from 1640 to 1668, marked the end of Philip IV's rule in Portugal. The war began when the Portuguese revolted against Spanish rule, which had been imposed on them since 1580. The Portuguese were successful in their revolt, and in 1668, Portugal regained its independence.