Under Nicholas I, the Principality of Montenegro vastly advanced and enlarged several times in the Montenegro-Turkish Wars and achieved recognition of independence in 1878. Modernization of the state followed, culminating with the draft of a Constitution in 1905. Political rifts for the first time emerged between the reigning People's Party that supported democratization of the ruler's autocratic regime and unconditional union with Serbia and the minor pro-monarch True People's Party. In 1910 Montenegro became a Kingdom. It initiated the Balkan wars in 1912 and 1913 in which the Ottomans lost all lands in the Balkans, achieving a common border with Serbia, but the Skadar was awarded to a newly created Albania. In World War I in 1914 Montenegro sided with Serbia against the Central Powers, suffering a full scale defeat to Austria-Hungary in early 1916. In 1918 the Allies liberated Montenegro, which was subsequently merged with Serbia. In 1904 Montenegro declared war on Japan in support of Russia. However, Montenegro inexplicably failed to adhere to the Treaty of Portsmouth in 1905 and so remained at war with Japan until 1918, although no hostilities occurred.
Faced with Russia, Austria–Hungary could spare only one-third of its army to attack Serbia. After suffering heavy losses, the Austrians briefly occupied the Serbian capital, Belgrade. A Serbian counterattack in the battle of Kolubara, however, succeeded in driving them from the country by the end of 1914. For the first ten months of 1915, Austria–Hungary used most of its military reserves to fight Italy. German and Austro-Hungarian diplomats, however, scored a coup by persuading Bulgaria to join in attacking Serbia. The Austro-Hungarian provinces of Slovenia, Croatia and Bosnia provided troops for Austria–Hungary, invading Serbia as well as fighting Russia and Italy. Montenegro allied itself with Serbia.