China faced increasing foreign imperialism in the 19th century, particularly from Britain due to the opium trade. This led to the Opium Wars in 1839-1842 and the Treaty of Nanking, which granted European powers extraterritorial rights in China and opened more ports to foreign trade. Meanwhile, Japan modernized under the Meiji Restoration to avoid foreign domination, developing a strong military and industrial economy to defeat China in the Sino-Japanese War of 1894-1895 and Russia in the Russo-Japanese War of 1904-1905, allowing Japan to exert control over Korea and Manchuria.