During the rule of Charlemagne, Pope Leo the Third found himself in grave danger. Charlemagne Jumped in to help the Pope. In return, The Pope decided to name him Empereror
You my new bishop
And you are no longer the Pope
Charlemagne's coronation was one to be remember for years later. It symbolized that the pope had the power to appoint an emperor. Charlemagne believed it was God who crowned him emperor but Pope Leo though the church had crowned him.
Happily ever after
Concordat of worms
200 years later, Pope Gregory claimed that he held the power to appoint bishops. He also claimed to have the ability to de-thrown an emperor. The King at the time, King Henry the Fourth, took this as a direct attack to his rights.
Due to this, King Henry the Fourth struck back. He appointed his own bishop in disregard to what the pope had said. He even tried to take the Popes titles away from him.
Eventually the church and the church of the holy Roman empire created an agreement. It was called the Concordat of Worms. This allowed the Pope to apoint bishops, but the king/emperor was able to give fiefs to the bishop in returor loyalty.
This system worked for awhile. Eventually this sytem would fail and things would fall back into chaos.