A castle was founded in the 11th century on the site of an earlier enclosure, and until the end of the 12th century this was the seat of appanaged Přemyslid princes. In 1063 Vratislav II founded a bishopric in the bailey, which in 1131 was moved inside the castle proper. A royal borough was established in 1253, which later obtained Magdeburg rights. It was here that in 1306 Wenceslas III, the last of the Přemyslids, was murdered. Charles IV stayed in the town often while he was Margrave of Moravia, and had the Moravian public records (tabulae terrae) kept here. During the Hussite Wars the town stood on the side of Sigismund, and during the conflict with George of Poděbrady on the side of the Hungarian King Matthias Corvinus, who in 1469 proclaimed himself King of Bohemia here. In 1573 the local Jesuit academy (founded in 1566) became a university. In 1619 the town participated in the Bohemian Estates’ Uprising, and expelled the Jesuits. The town suffered greatly during the Thirty Years’ War and from 1642 to 1650 was held by the Swedes; it was at this time that Brno became the capital of Moravia. In 1777 the bishopric became an archbishopric. In 1741 Olomouc was occupied by the Prussians. Between 1742 and 1754 the city was transformed into a Baroque fortress, which survived the Prussian siege of 1758 but limited growth (and was decommissioned in 1888). In the revolutionary year of 1848 the Viennese Court found refuge here, and it was here that Emperor Ferdinand V ascended to the throne. The town developed further only after the First World War.
Comenius apparently participated in the welcoming of Frederick V of the Palatinate to Olomouc in 1620.