When lured to a banquet and then confronted with Frederick's armed guards, John was forced to hand over the regency, and Cyprus, to Emperor Frederick's control, under Amalric Barlais. However, this was temporary, as John later resisted with military force. After Frederick departed from the island in April, John's forces defeated the remaining imperial bailiffs in a battle outside Nicosia on July 14, 1229, thus beginning the War of the Lombards. Frederick sent an army in 1231, under the marshal of the Empire, which attempted to invade Cyprus. John was able to repel the invasion at the Battle of Agridi, but the imperial fleet sailed to John's power center of Beirut, which they besieged and almost captured. The imperial marshal, Richard Filangieri, was able to establish himself in Jerusalem and Tyre, which he had regained by treaty in 1229, but not in Beirut or the capital in Acre. In Acre, John's supporters formed a commune, of which John himself was elected mayor when he arrived in 1232. The Commune of Acre was able to relieve the siege of Beirut, but in John's absence from Cyprus, the supporters of the Lusignans took control. In any case, the boy Henry I of Cyprus came of age in the same year, and John's regency was no longer necessary. When Henry I succeeded to the throne, both John and Riccardo immediately raced back to Cyprus, where the imperial forces were defeated in battle on June 15. Henry became undisputed king of Cyprus, and since he supported the Ibelins over the Lusignans, John's family remained influential. Conflict continued, as Filangieri remained in control of Jerusalem and Tyre, and had the support of Bohemund IV of Antioch, the Teutonic Knights, the Knights Hospitaller, and the Pisan merchants. John, for his part, was supported by his nobles on Cyprus, and in his continental holdings in Beirut, Caesarea, and Arsuf, as well as by the Knights Templar and the Genoese merchant community. Neither side could make any headway, and in 1234 Pope Gregory IX excommunicated John and his supporters. This was partly revoked in 1235, but still no peace could be made. In the last year of his life, John of Ibelin, as did many other elderly barons, joined the order of the Knights Templar, so that he could die as a Templar. His family was opposed to this, but John insisted, and was honored with a grand