The German Emperors

Meanwhile, in northern Italy, Magyars (Hungarians) had begun raiding Lombardy in the mid-10th century. Otto I (the Great), king of Germany, defeated them at Lechfeld in 955. In 962 he came to the aid of Pope John XII, whose authority was being challenged by Lombard nobles. Otto drove the nobles out of Rome, and the pope proclaimed him emperor of the Western Roman Empire, which came to be known as the Holy Roman Empire.

Most of Otto's successors were too preoccupied with German affairs to maintain control over the Lombard nobles. In 1046 Emperor Henry III brought an army to Rome to help restore order in the Papal States. However, a conflict developed between the emperor and the pope over lay investiture (the installation of bishops by monarchs). The conflict divided the Italian nobility. Supporters of the emperor came to be known as Ghibellines; supporters of the pope were called Guelphs.

During the reigns of Henry IV (1056–1106), Henry V (1106–25), and Frederick (I) Barbarossa (1152–90), German armies marched on Rome and Lombardy several times. In 1164 the Guelph nobles formed an alliance called the Lombard League. Fighting continued until the League defeated Frederick at Legnano in 1176.

In 1194 the Kingdom of the Two Sicilies passed by marriage to Emperor Henry VI, the son of Frederick Barbarossa. Henry's son, Frederick II (1215–50), resumed the war against the Lombard League but was defeated.

After Frederick's death, Charles of Anjou, a French noble, seized the Kingdom of the Two Sicilies (1266–68) with the support of the Guelphs. With this setback, German efforts to rule Italy came to an end. An uprising against the French broke out in 1282. The revolt, commonly known as the Sicilian Vespers, was supported by the Kingdom of Aragon (later part of the Kingdom of Spain) and succeeded in Sicily. However, Charles maintained the Angevin holdings in southern Italy.