In January 1077 Henry crossed the Alps in winter and came to the castle of Canossa in the Apennines, where Gregory was staying with the countess Matilda of Tuscany. The accounts, including Gregory's own letter, describe the king standing outside the walls for three days in penitential dress in the snow, until the pope absolved him. Going to Canossa entered European languages as a phrase for humiliating submission.
It was also a defeat for the pope, and he seems to have known it. Absolving a penitent was something Gregory could not refuse without abandoning the ground he stood on, and the absolution removed the excommunication that the German princes had been intending to use. Henry recovered his position, dealt with the rival king the princes had elected anyway, and returned to the quarrel from strength.
Gregory excommunicated him a second time in 1080. This time the effect was small; Henry had a synod declare an antipope, marched into Italy, and took Rome in 1084. Gregory held out in the Castel Sant'Angelo and was rescued by Norman troops from the south, who then sacked the city so thoroughly that the Romans turned against him. He left with them and died at Salerno the following year. His reported last words were that he had loved righteousness and hated iniquity, and therefore died in exile.
The specific question was settled after both men were dead, by the Concordat of Worms in 1122, which separated the spiritual investiture from the grant of lands and let each side claim it had won.