Macau was established as a trading post in 1557 permanently leased to the Kingdom of Portugal by the Ming dynasty. The territory was later fully ceded in the 1887 Sino-Portuguese Treaty of Peking, but returned to China in 1999. Following the 1974 Carnation Revolution, Portugal formally relinquished Macau as an overseas province in 1976 and acknowledged it as a "Chinese territory under Portuguese administration." After negotiations on Hong Kong's future had concluded, China and Portugal began deliberations on Macau in 1986 and agreed on the Sino-Portuguese Joint Declaration in 1987. Macau would be transferred to China in 1999 and governed largely under the same terms as Hong Kong.