In 774 AD, Charlemagne conquered northern Italy from the Lombards. Soon after that Charlemagne got the Pope to name him the Holy Roman Emperor. For the next three hundred years, northern Italy was in the hands of the Holy Roman Emperor. That is, it belonged to the sons and grandsons of Charlemagne, and then to the men who took over ruling the Holy Roman Empire. Basically these men ruled Germany and Austria. They tended to live in Germany. So northern Italy was ruled by far-away German kings who only came to Italy once in a while.
In 774 AD, central and southern Italy still belonged to the old Roman Empire. But the emperors in Constantinople were busy trying to protect their kingdom from the Abbasids, and had no time or soldiers to spare for Italy. So the Popes in Rome, with the help of the kings of France, became the main leaders of central and southern Italy.
By 830 AD, however, the Abbasids conquered Sicily and southern Italy, as part of their general conquest of the Mediterranean Sea. So three different groups of people ruled Italy: the Islamic Empire ruled southern Italy, the Popes ruled the middle, and the Holy Roman Empire ruled northern Italy.