During his father's lifetime he ruled Moravia, but when in 1248 some discontented Bohemian nobles acknowledged him as their sovereign, trouble arose between him and his father, and for a short time Ottokar was imprisoned. However, in 1251 the young prince secured his election as duke of Austria, where he strengthened his position by marrying Margaret († 1267), sister of Duke Frederick II, the last of the Babenberg rulers of the duchy and widow of the German king, Henry VII. Some years later he repudiated this lady and married a Hungarian princess.
Both before and after he became king of Bohemia in succession to his father in September 1253 Ottokar was involved in a dispute with Bela IV, king of Hungary, over the possession of Styria, which duchy had formerly been united with Austria. By an arrangement made in 1254 he surrendered part of it to Bela, but when the dispute was renewed he defeated the Hungarians in July 1260 near Kressenbrunn and secured the whole of Styria for himself, owing his formal investiture with Austria and Styria to the German king, Richard, Earl of Cornwall.
In 1269 he inherited Carinthia and part of Carniola, and having made good his claim, contested by the Hungarians, on the field of battle, he was the most powerful prince within empire when an election for the German throne took place in 1273. But Ottokar was not the successful candidate. He refused to acknowledge his victorious rival, Rudolph of Habsburg, and urged the pope to adopt a similar attitude, while the new king claimed the Austrian duchies. Matters reached a climax in 1276. Placing Ottakar under the ban of the empire, Rudolph besieged Vienna and compelled Ottakar in November 1276 to sign a treaty by which he gave up Austria and the neighbouring duchies, retaining for himself only Bohemia and Moravia. Two years later the Czech king tried to recover his lost lands, he found allies and collected a large army, but he was defeated by Rudolph and killed at Dürnkrut on the March on August 26, 1278.
Ottokar was a founder of towns and a friend of law and order, while he assisted trade and welcomed German immigrants. He is a famous figure both in history and in legend. He was called the "Iron and Gold King" throughout Europe and Dante described him in the Divine Comedy as one of the greatest contemporaries. His son and successor was Wenceslaus II.