In Catholicism, the doctrine (or theory) of the two swords is an exegesis of Luke 22:38 elaborated in the Middle Ages.
It can be understood as a particular justification for the Gelasian doctrine of "the sacred authority of the priesthood and the royal power".
It was later taken up by Gottschalk of Aachen on behalf of the Emperor Henry IV (1056–1105) against the claims of Pope Gregory VII (1073–1085) during the Investiture Contest.
[1] By the early 13th century, the two swords were the subject of serious study and debate among canon lawyers and decretalists.
When Pope Gregory IX started the War of the Keys against Emperor Frederick II in 1228, it was on the basis of a claim to control both swords.