It was one of the cities of the Pentapolis under the exarchate of Ravenna, the other four being Fano, Pesaro, Senigallia and Rimini, and eventually became a semi-independent republic under the protection of the popes, until Gonzaga took possession of it for Clement Vii.