From the eleventh century onwards, Bergamo is an independent commune, taking part in the Lombard League that defeats Frederick I Barbarossa in 1165.
Caught in the bitter fights between Guelphs and Ghibellines, led in the city by the Colleoni and the Suardi respectively, from 1264 Bergamo is intermittently under the rule of Milan.
In 1331, it gives itself to John of Bohemia, but later the Visconti of Milan reconquer it.