In the 11th century, the First Bulgarian Empire collapsed under Rus' and Byzantine attacks, and became part of the Byzantine Empire until 1185. Then, a major uprising led by two brothers, Asen and Peter of the Asen dynasty, restored the Bulgarian state to form the Second Bulgarian Empire. After reaching its apogee in the 1230s, Bulgaria started to decline due to a number of factors, most notably its geographic position which rendered it vulnerable to simultaneous attacks and invasions from many sides. A peasant rebellion, one of the few successful such in history, established the swineherd Ivaylo as a Tsar. His short reign was essential in recovering—at least partially—the integrity of the Bulgarian state. A relatively thriving period followed after 1300, but ended in 1371, when factional divisions caused Bulgaria to split into three small Tsardoms. By 1396, they were subjugated by the Ottoman Empire. The Turks eliminated the Bulgarian system of nobility and ruling clergy, and Bulgaria remained an integral Ottoman Empire territory for the next 500 years.