The occupation was enforced following the defeat of the First Serbian Uprising (1804–1813), during which Serbia existed as a de facto independent state for over a decade.
After the failure of this revolt, the Turks inflicted more persecution against the Serbs, such as high taxation, forced labor, and rape.
The Serbs fought in battles at Rudnik, Ljubić, Palež, Valjevo, Čačak, Karanovac, Požarevac, Kragujevac, Jagodina, and Dublje and drove the Ottomans out of the Pashalik of Belgrade.
Although the principality paid a yearly tax to the Porte and had a garrison of Ottoman troops in Belgrade until 1867, it was, in most other matters, an independent state.
Under the grandson of Miloš's brother, Milan, Serbia gained formal independence in 1878 under the Treaty of Berlin.
In 1817, Miloš Obrenović succeeded in forcing Marashli Ali Pasha to negotiate an unwritten agreement, an act which effectively ended the Second Serbian uprising.
It introduced the Serbian Parliament on the regular basis and established the Obrenović dynasty as the legal heir to the throne of Serbia.