Tangier was ceded to England in 1661 in order to encourage England to support Portugal in the Portuguese Restoration War, and Ceuta was finally handed over to Spain in 1668 through the Treaty of Lisbon, which finally recognized the House of Braganza as Portugal's new ruling dynasty and its rule over Portugal's remaining overseas colonies. These events essentially ended Portugal's direct involvement in Morocco, until they abandoned Mazagan under the pressure of Mohammed ben Abdallah in 1769.