The oldest known inhabitants of what is now Montenegro were the Illyrian tribes who were subdued by the Romans in 9AD and then marginalised by the mass immigration of Slavs in the fifth and sixth centuries. The principality of Duklja that the Slavic newcomers founded became independent from the Byzantine Empire in 1042 and soon became a kingdom, expanding to incorporate surrounding areas. In the early medieval era the region was ruled alternatively by local families and the medieval Serbian state until the Ottomans occupied the region in 1499.
The Ottoman era
Montenegro remained relatively autonomous within the Ottoman empire, with local noble families allowed to rule the area with little interference. Despite this, the occupation was never accepted and several uprisings occurred until the Ottomans were finally defeated in the late 17th century. Under Prince-Bishops Petar I and II Petrović-Njegoš, Montenegro unified and became a theocracy.
Nicholas I greatly expanded and modernised the principality in the 20th century, winning recognition of independence from the Ottoman Empire in 1878.