In 1089 the parliament rebelled in Croatia. During this uprising, Zvonimir was killed, or, according to another version, committed suicide. The king did not leave heirs, so again they had to look for a representative from the side branch of Trpimirovich. Stephan II, Petar Kresimir’s nephew, was invited to the Croatian throne. Stephan was by that time very old and reigned for only two years (1089-1091). With his old age, Stephan made the Croats think about a possible heir. Stephan II was the last representative of the Trpimirovich family, therefore the most realistic candidate for the throne was Louis I the Holy King of Hungary from the Arpad dynasty, whose sister Elena was the wife of the last king, Zvonimir. The army of Louis entered Croatia immediately after the death of Stephan II and occupied all of Pannonia. Elena temporarily became the Queen of Croatia (rules for some time in 1091 ). The dynasty of Trpimirovic was interrupted. Against the Hungarians, the Byzantine emperor Alexios I Komnenos spoke out, who sent the Polovtsi army to stop the Hungarians. Louis left Croatia, but retained Slavonia, where the son of the king of Geza and the nephew of Louis, Prince Almos, was imprisoned. Soon, Queen Elema renounced the title in favor of Almos.
In 1093 the Croatian nobility rebelled against Hungarian domination. They declared Almos deposed and raised to the throne a new king, Petar Svachic . He managed to unite the kingdom and expel Almos from Slavonia in 1095. In the same year, King Louis died, and the Croats were counting on the cessation of Hungarian pressure. However, the new king, brother of Almos and nephew of Louis, did not tolerate a similar development of events in Croatia. He enlisted the support of Pope Urban II and in 1097 sent troops to Croatia. The decisive battle of this campaign was the battle on Mount Gvozd (modern Petrova Mountain ). In this battle, Petar Svacic was killed.
Union of Croatia and Hungary
Kalman , establishing his power in Croatia, began the so-called period of the Croatian-Hungarian union. The union tried to break the Croatian nobility, when Kalman was forced to withdraw troops from Croatia to fight the Ruthenians and the Cumans in Galicia (1099 ). But this attempt of the Croatian nobles failed.
Kalman returned from a campaign in 1102. This year, he began negotiations with the Croats, which ended with the signing of the Pacta conventa, a treaty in which Croatia lost its independence and was completely part of Hungary, with all lands, cities and islands. The Croats recognized Kalman as their king, and in return he promised not to violate the foundations and traditions of Croatia, left parliament and ban title, and created autonomy for Croatia. The Croats did not pay taxes to the Hungarian king. The residence of the Croatian rulers was again transferred and Kalman’s descendants for some time, until Bela IV came to power, added the title “King of Croatia” to the title of King of Hungary.
The exact time of the creation of Pacta Conventa and the terms from this document later became a point of contention. Nevertheless, Croatia has maintained its traditions even under the rule of Hungary. He was in charge of Croatian affairs, Sabor, and the title of the viceroy of Hungary in Croatia belonged to the ban of Croatia. Throughout, the union of Croatia will be in autonomy and will remain a separate crown.