Answer
Frederick II was excommunicated three times. The first excommunication was in 1227 by Pope Gregory IX, for Frederick's failure to go on crusade. The second excommunication was in 1239 by Pope Innocent IV, for Frederick's invasion of the Papal States. The third and final excommunication was in 1245 by Pope Innocent IV, for Frederick's refusal to submit to the pope's authority.