The history of Rome in the Middle Ages, bewildering in its detail, is essentially that of two institutions, the papacy and the commune of Rome. In the 5th cent. the Goths ruled Italy from Ravenna, their capital. Odoacer and Theodoric the Great kept the old administration of Rome under Roman law, with Roman officials. The city, whose population was to remain less than 50,000 throughout the Middle Ages, suffered severely from the wars between the Goths and Byzantines. In 552, Narses conquered Rome for Byzantium and became the first of the exarchs (viceroys) who ruled Italy from Ravenna. Under Byzantine rule commerce declined, and the senate and consuls disappeared.
Pope Gregory I (590–604), one of the greatest Roman leaders of all time, began to emancipate Rome from the exarchs. Sustained by the people, the popes soon exercised greater power in Rome than did the imperial governors, and many secular buildings were converted into churches. The papal elections were, for the next 12 centuries, the main events in Roman history. Two other far-reaching developments (7th–8th cent.) were the division of the people into four classes (clergy, nobility, soldiers, and the lowest class) and the emergence of the Papal States.
The coronation (800) at Rome of Charlemagne as emperor of the West ended all question of Byzantine suzerainty over Rome, but it also inaugurated an era characterized by the ambiguous relationship between the emperors and the popes. That era was punctuated by visits to the city by the German kings, to be crowned emperor or to secure the election of a pope to their liking or to impose their will on the pope. In 846, Rome was sacked by the Arabs; the Leonine walls were built to protect the city, but they did not prevent the frequent occupations and plunderings of the city by Christian powers.
By the 10th cent., Rome and the papacy had reached their lowest point. Papal elections, originally exercised by the citizens of Rome, had come under the control of the great noble families, among whom the Frangipani and Pierleone families and later the Orsini and the Colonna were the most powerful. Each of these would rather have torn Rome apart than allowed the other families to gain undue influence. They built fortresses in the city (often improvised transformations of the ancient palaces and theaters) and ruled Rome from them.
From 932 to 954, Alberic, a very able man, governed Rome firmly and restored its self-respect, but after his death and after the proceedings that accompanied the coronation of Otto I as emperor, Rome relapsed into chaos, and the papal dignity once more became the pawn of the emperors and of local feudatories. Contending factions often elected several popes at once. Gregory VII reformed these abuses and strongly claimed the supremacy of the church over the municipality, but he himself ended as an exile, Emperor Henry IV having taken Rome in 1084. The Normans under Robert Guiscard came to rescue Gregory and thoroughly sacked the city on the same occasion (1084).
Papal authority was challenged in the 12th cent. by the communal movement. A commune was set up (1144–55), led by Arnold of Brescia, but it was subdued by the intervention of Emperor Frederick I. Finally, a republic under papal patronage was established, headed by an elected senator. However, civil strife continued between popular and aristocratic factions and between Guelphs and Ghibellines. The commune made war to subdue neighboring cities, for it pretended to rule over the Papal States, particularly the duchy of Rome, which included Latium and parts of Tuscany. Innocent III controlled the government of the city, but it regained its autonomy after the accession of Emperor Frederick II. Later in the 13th cent. foreign senators began to be chosen; among them were Brancaleone degli Andalò (1252–58) and Charles I of Naples.
During the "Babylonian captivity" of the popes at Avignon (1309–78) Rome was desolate, economically ruined, and in constant turmoil. Cola di Rienzi became the champion of the people and tried to revive the ancient Roman institutions, as envisaged also by Petrarch and Dante; in 1347 he was made tribune, but his dreams were doomed. Cardinal Albornoz temporarily restored the papal authority over Rome, but the Great Schism (1378–1417) intervened. Once more a republic was set up. In 1420, Martin V returned to Rome, and with him began the true and effective dominion of the popes in Rome.