With the exarchate of Ravenna, it passed under papal authority. In the ninth century, Fausto Alidosi defended the city against the Saracens and Hungarians. In the tenth century, Troilo Nordiglio acquired great power. This and the following centuries witnessed incessant wars against the Ravennatese, the Faentines and the Bolognese, as well as the internecine struggles of the Castrimolesi (from "Castro Imolese", "castle of Imola") and the "Sancassianesi" (from San Cassiano). Amid these conflicts, the republican constitution of the city was created. In the contest between pope and emperor, Imola was generally Ghibelline, though it often returned to the popes (e.g. in 1248). Several times, powerful lords attempted to obtain the mastery of the city (Alidosi, 1292; Maghinardo Pagano, 1295). Pope Benedict XII turned the city and its territory over to Lippo II Alidosi with the title of pontifical vicar, the power remaining in the family Alidosi until 1424, when the condottiero Angelo della Pergola, "capitano" for Filippo Maria Visconti, gained the supremacy (see also Wars in Lombardy). In 1426 the city was restored to the Holy See, and the legate (later Cardinal) Capranica inaugurated a new regime in public affairs.