In 1812 the Russian Empire and the Ottoman Empire signed the Treaty of Bucharest (1812), by which Russia annexed the eastern part of the medieval Principality of Moldavia. This territory became known as Bessarabia. Between 1859 and 1866, Principality of Moldavia and the neighbouring Principality of Wallachia united into a single country called Romania. In 1917, when the Russian Empire was disintegrating, a Moldavian Democratic Republic was formed in Bessarabia. In 1918, after the Romanian army gained control of the region, Sfatul Țării proclaimed the independence of the Moldavian Republic and, later, voted for the union with Romania. The Soviet Russia contested the outcome of these events and, in May 1919, proclaimed the Bessarabian Soviet Socialist Republic as a government in exile. After the Soviet-organized Tatarbunary Uprising failed, in 1924 a Moldavian ASSR (MASSR) was created within the Ukrainian SSR, just east of the river Dniester that then marked the boundary between Romania and the Soviet Union.