The Investiture Controversy was a dispute between the Pope and the Holy Roman Emperor over who was allowed to appoint, or invest, bishops. It began in 1075 when Pope Gregory VII stated that only the pope, not emperors or kings, could appoint clergy.
Henry IV, the Holy Roman Emperor, wrote a stinging rebuttal to the pope's claim in which he said that he had the power to appoint bishops and install his own candidate as Bishop of Milan even though the pope had already chosen another candidate for the job. The pope then excommunicated Henry and negated his kingship, which caused the nobles who had previously been under Henry's sway to take over his lands for themselves.
Chastened, Henry apologized to the pope and, for the time being, ceased investing bishops. The Investiture Controversy continued to flare up for several years until the compromises achieved in the Concordat of Worms in 1122.