 Queen Gundeberga, daughter of Theodolinda and wife of Arioald, after being charged with the betrayal of her husband, was imprisoned in a tower in 629 and released after three years, thanks to the first "Judgement of God" ever celebrated in Italy.In the Carolingian period, it was the place of a comitatus and in 1024 the fortress of Lomello was elected to the residence of the Palatine Counts while, in the same years, the basilica of Santa Maria Maggiore was built as a mark of wealth and power.The commune of Pavia defeated the Counts in the 1140s and captured Lomello, owning it until 1360, when Lomello came under the domination of the Visconti, who were followed, from 1450 to 1535, by the Sforza.