After the end of the Russo-Japanese War in 1905 with the Treaty of Portsmouth, the southern half of Sakhalin officially became Japanese territory, and was renamed as Karafuto, prompting an influx of Japanese settlers there. Japanese settled in the northern half of Karafuto; after Japan agreed to hand this half back to the Soviet Union, some may have chosen to remain north of the Soviet line of control. However, the majority would remain in Japanese territory until the closing days of World War II, when the whole of Sakhalin came under Soviet control as part of the USSR's invasion of Manchuria; most Japanese fled the advancing Red Army, or returned to Japan after the Soviet takeover, but others, mainly military personnel, were taken to the mainland of Russia and detained in work camps there. Furthermore, roughly 40,000 Korean settlers, despite still holding Japanese nationality, were denied permission by the Soviet Government to transit through Japan to repatriate to their homes in the southern half of the Korean peninsula. They were either told to take North Korean citizenship or take Soviet citizenship. Known as Sakhalin Koreans, they were trapped on the island for almost four decades.