Byzantine-Hungarian War
In 1163, Emperor Manuel I Comnenus came to Niš with the army via Serdica (Sofia), where, according to John Kinnamos, he decided "to deal with things concerning Serbia". At that time, Serbia was ruled by the Grand Župan Desa, an ally of Stephen III in the Hungarian dynastic conflicts, and thus an opponent of Manuel. When in 1165 Desa was finally forced to come to Niš before the emperor, his connections with the Hungarian king Stephen III were revealed, Desa called him his master, Manuel I decided to take him to court and punish him. Desa was first detained and kept under guard, and then sent to the court prison in Constantinople.
The land was given by the emperor to the administration of Zavida's sons, who were in the pro-Byzantine party: Tihomir, Stracimir, Miroslav and the youngest Nemanja. Tihomir was the oldest and became the Grand Župan of Serbia. In January 1166, Tihomir was recognized by the brothers who were given to rule other certain parts of Serbia and the Serbian-Byzantine frontier. Stracimir held the areas around West Morava, Miroslav Zahumlje, while Stefan Nemanja was given the areas around Ibar, Toplica and Dubočica (around Leskovac), which probably was historical region of Dendra west of Niš.
The Byzantine emperor Manuel I Comnenus launched a large army against Hungary because he was informed of their dissatisfaction and internal conflicts. The Hungarian prince Béla III had to live in Constantinople, where he was married, and Béla's lands, Dalmatia with southern Hungary (below Velebit), had to come under Constantinople's rule. There is resistance in Hungary, which is why Emperor Manuel embarks on a campaign. The Byzantine army conquered Zemun and Srem in 1165. The Byzantines were accompanied by the obligatory detachments of Serbs. The second Byzantine army under command of John Doukas Komnenos moved west, across Serbia and Bosnia towards the Adriatic coast. Without significant resistance, they took all the cities from Split to Bar, forcing them to recognize Byzantine rule.
The Byzantines also had success in a campaign in Italy where they captured an important seaport on the west coast of the Adriatic, Ancona. Venice, which had previously turned to Byzantium for help during the conquest of Friedrich Barbarossa in northern Italy, changed its attitude towards the Byzantines for fear of losing the Adriatic. It approached Hungary as a natural ally against the Byzantines. At the same time, they began to work among the Serbs, especially in Serbia, in order to rebel against Byzantium.
In 1166, the Hungarians counterattacked to push Byzantium out of the newly conquered areas. However, in response, Emperor Manuel launched three armies against Hungary, one from the Danube, and the other two across the Carpathians, towards the center of Pannonia. While the main Hungarian army was operating towards the Danube, Belgrade and Braničevo, two Byzantine armies went deep into their territory, causing general panic. The Hungarians were forced to seek peace through intermediaries to their detriment in 1167.
As the ideal candidate of Venice and Hungary among the Serbs appeared Nemanja, when his brothers and, above all, Tihomir imprisoned him in a cave near Fortress Ras. Nemanja probably hoped that he would take the place of Desa, as the former representative of the pro-Greek party, while Emperor Manuel brought his eldest brother Tihomir to the throne. Angry because of that, Nemanja changes his policy in favor of Hungary and its allies. Nemanja escaped from the dungeon, it is not known with whose help. Nemanja's son and biographer, Stefan Nemanjić, describing his father's life, says how he escaped with the help of "heavenly forces": "And this again, because of meekness and justice, and wonderful humility, and because of all good customs, with a high arm he brought him out of the rocky cave, and brought him to the throne of his fatherland, and raised him up as the great lord of all the world."