Charlemagne was a devout Christian king. His goal was to build a large Christian empire. This is because he believed that God wanted him to improve the Church.
Pope Gregory was being threatened to be put out of office. He had to flee to escape because he was undefended. So he ran to Charlemagne for help.
ARE YOU INSANE?
You are excommunicated from the church
When Pope Gregory fled he begged Charlemagne for protection. Charlemagne agreed to protect him as he regained his spot in office. The Pope then crowned Charlemagne emperor in return, although he believed the church crowned Charlemagne, and not himself.
Concordat of Worms
This is how it be...
Under Charlemagne's protection the pope was returned to his rightful place. The pope then crowned Charlemagne emperor. Although he believed that that the church had crowned the emperor and not himself.
200 years later, Pope Gregory, claimed that the church had all the authority to choose the bishops. King Henry disagreed with his decision and continued to choose bishops. After that, the Pope banned him from the church which at the time made him an outcast.
After many years the Pope and the King made a contract known as the Concordat of Worms. This put the people at peace because they began taking sides and separating the country. Although this problem was resolved the Pope and Kings had many other issues.