By the second half of the thirteenth century, however, internal conditions in the country had deteriorated. The feudal system, which had been further consolidated during the thirteenth century, had exacerbated the tensions of the peasants, and hostilities among the boyars increased. The throne was contested between 1257 and 1277 and was eventually taken forcibly by Ivailo, known as the swineherd tsar because of his leadership of a peasant uprising in 1277.
Meanwhile, Bulgaria's neighbors again sensed an opportune time to attack because of the internal divisions in the country. The Byzantines conquered several parts of Macedonia and Thrace, and the Hungarians and Tatars invaded on another front. At one point the Hungarian king declared himself king of Bulgaria. In 1242 there was a large-scale Mongol invasion. Tatar raids went on continually between 1241 and 1300. The country was totally fragmented; each separate area attempted to ally itself with its former enemies, whether Russian, Hungarian, or Tatar, in order to prevent widespread damage.
By the fourteenth century the Turks began to envision the conquest of Bulgaria. Internally the boyars continued to fight among themselves, and externally the country was threatened alternately by Byzantium and by Serbia. By the mid-fourteenth century all of Macedonia was under Serbian control, and the Serbian tsar--much like the Hungarian king before him--called himself the tsar of the Bulgars. The area of the country retained by the Bulgars by this time was divided into three parts: the last Bulgarian tsar maintained his capital at Turnovo in the central highlands; the so-called Vidin Kingdom, ruled by the tsar's brother, existed in the far northwest; and a principality of Dobrudzha was established in the northeast.
At the same time the Ottoman Turks were beginning to advance. Having seized areas of Asia Minor, they proceeded to raid the Balkans from 1326 to 1352. Under their leader, Murad I, they began to attack Thrace, Macedonia, and parts of Bulgaria. By 1371 they were attacking territories in northeastern Thrace. At this point they marched against Sofia and, despite active resistance, succeeded in capturing it. Despite an alliance with the Serbs, the Bulgarians were too weak to resist further; in 1388 the Turks easily won a battle against the Serbs. The fall of Turnovo was followed by the fall of Vidin and Dobrudzha. By 1396 all of Bulgaria was under Turkish domination.