After the Russo-Turkish War of 1877–1878, the 1878 Treaty of Berlin set up an autonomous state, the Principality of Bulgaria, within the Ottoman Empire. Although remaining under Ottoman sovereignty, it functioned independently, taking Alexander of Battenberg as its first prince in 1879. In 1885 Alexander took control of the still-Ottoman Eastern Rumelia, officially under a personal union. Following Prince Alexander's abdication (1886), a Bulgarian Assembly elected Ferdinand I as prince in 1887. Full independence from Ottoman control was declared in 1908.
In the 1912–1913 Balkan Wars, Bulgaria initially formed an alliance with Greece, Serbia and Montenegro against the Ottoman Empire, and together they conquered a great deal of Ottoman territory.