When Stjepan II died in 1091, ending the Trpimirović dynasty rule in the medieval kingdom of Croatia, Ladislaus I of Hungary claimed the Croatian crown. Opposition to the claim led to a war and the personal union of Croatia and Hungary in 1102, ruled by Coloman. For the next four centuries, Croatia was ruled by the Sabor (parliament) and a Ban of Croatia (viceroy) appointed by the king. This period saw an increasing threat of Ottoman conquest and a struggle against the Republic of Venice for control of coastal areas. The Venetians gained control over most of Dalmatia by 1428 except for the city-state of Dubrovnik, which became independent. Ottoman conquests led to the 1493 Battle of Krbava Field and the 1526 Battle of Mohács, both ending in decisive Ottoman victories against Hungarian and Croatian armies. King Louis II died at Mohács; in 1527, the assembly of Croatian nobility meeting at Cetin chose Ferdinand I of the House of Habsburg as the new ruler of Croatia under the conditions that he provide protection to Croatia against the Ottoman Empire and respect its political rights. In political disarray, the divided Hungarian nobility elected two kings simultaneously: János Szapolyai and Ferdinand I. With the conquest of Buda by the Ottomans in 1541, the remaining part of Hungary not ruled by the Ottomans (known as the Royal Hungary) was annexed by the Habsburgs; they ruled as Kings of Hungary, thus keeping the kingdoms of Hungary and Croatia under a single crown.