Karafuto became territory of the Empire of Japan in 1905 after the Russo-Japanese War when the portion of Sakhalin south of 50°N was ceded from the Russian Empire in the Treaty of Portsmouth. Karafuto was established in 1907 as an external territory until being upgraded to an "Inner Land" of the Japanese metropole in 1943. Ōtomari (Korsakov) was the capital of Karafuto from 1905 to 1908 and Toyohara (Yuzhno-Sakhalinsk) from 1908 to August 1945 when the Japanese administration ceased to function in the invasion of South Sakhalin by the Soviet Union after the surrender of Japan in World War II. Karafuto Prefecture was "de facto" replaced with Sakhalin Oblast, although it continued to exist "de jure" under Japanese law until it was formally abolished as a legal entity by Japan on June 1, 1949.