The Principality of Serbia (Serbian: Кнежевина Србија / Kneževina Srbija) was a semi-independent state in the Balkans that came into existence as a result of the Serbian Revolution which lasted between 1804 and 1817. Its creation was negotiated first through an unwritten agreement between Miloš Obrenović, leader of the Second Serbian Uprising and Ottoman official Marashli Pasha. It was followed by the series of legal documents published by the Porte in 1828, 1829 and finally, 1830 —-the Hatt-i Sharif.
At first, the principality included only the territory of the former Pashaluk of Belgrade, but in 1831–33 it expanded to the east, south, and west. On 18 April 1867 the Ottoman government ordered the Ottoman garrison which had been since 1826 the last representation of Ottoman suzerainty in Serbia withdrawn from the Belgrade fortress. The only stipulation was that the Ottoman flag continue to fly over the fortress alongside the Serbian one. Serbia's de facto independence dates from this event. A new Constitution in 1869 defined Serbia as an independent state. Serbia was further expanded to the south-east in 1878, when its independence from the Ottoman Empire won full international recognition at the Treaty of Berlin. The Principality would last until 1882 when it was raised to the level of the Kingdom of Serbia.