Following the defeat of the Magyars by Emperor Otto I at the Battle of Lechfeld in 955, Otto's ally Boleslaus I, the Přemyslid ruler of Bohemia, took control over Moravia. Bolesław I Chrobry of Poland annexed Moravia in 999, and ruled it until 1019, when the Přemyslid prince Bretislaus recaptured it. Upon his father's death in 1034, Bretislaus became the ruler of Bohemia. In 1055, he decreed that Bohemia and Moravia would be inherited together by primogeniture, although he also provided that his younger sons should govern parts (quarters) of Moravia as vassals to his oldest son.