Ioannina is first definitely mentioned in a 1020 decree by the Byzantine emperor Basil II, but it clearly existed for several centuries before. Traditionally, the foundation and first fortification of the city have been placed in the 6th century, when the historian Procopius (De Aedificiis, IV.1.39–42) records the construction of a new, "well-fortified" city by the Byzantine emperor Justinian I (r. 527–565) for the inhabitants of ancient Euroia. This view is not supported, however, by any concrete archaeological evidence. Early 21st-century excavations furthermore have brought to light fortifications dating to the Hellenistic period (4th–3rd centuries BC), the course of which was largely followed by later reconstruction of the fortress in the Byzantine and Ottoman periods. The identification of the site with one of the ancient cities of Epirus has not yet been possible. The Greek archaeologist K. Tsoures dated the Byzantine city walls and the northeastern citadel to the 10th century, with additions in the late 11th century, including the south-eastern citadel, traditionally ascribed to the short-lived occupation of the city by the Normans under the leadership of Bohemond of Taranto.
After the fall of the Byzantine Empire to the Fourth Crusade in 1204, the town's history was turbulent: it became part of the Byzantine Greek successor state of Epirus, fell to the restored Palaiologan Byzantine Empire in 1319, and was captured by the Serbian ruler Stefan Dushan in 1346. The Florentine adventurer Esau de' Buondelmonti captured the city from its Serbian rulers in 1385, to be followed by the Tocco family, rulers of Cephalonia and Zakynthos, from 1411 until the capture of the city by the Ottoman Empire on 9 October 1430. In the years immediately after 1204, the city walls and the northeastern citadel were reconstructed, while further reconstruction was undertaken in 1367–84 under Thomas Preljubović. The course of the Byzantine walls largely coincides with the extant fortification, but few details about it, such as the number and structure of the towers, were known until excavations during the last couple of decades.
The city remained under Ottoman rule from 1430 until captured by Greece in the First Balkan War in 1913. It enjoyed considerable prosperity, and reached the height of its pre-eminence under the rule of Ali Pasha, who became the ruler of a large semi-autonomous state encompassing much of modern-day Greece and Albania between 1787 and his downfall and execution in 1822. It is to the period of Ali Pasha's rule that the present form of the castle largely dates; the modifications or repairs undertaken on the Byzantine walls by previous Ottoman governors are now no longer discernible, as Ali Pasha initiated a wide-ranging reconstruction of the walls in the early 19th century, which was completed in 1815. It incorporated, as far as was possible, the pre-existing Byzantine fortifications, while adding a new wall in front. The interval was filled up with rubble or provided with arched galleries, forming a large terraced surface on top on which cannon could be installed.
Source: wikipedia.org