Milan became a free commune in the 12th century. In 1162 it was sacked by Frederick I Barbarossa. The formation of the Lombard League saw Milan eventually free of the Holy Roman Empire. Milan was however torn politically between Guelph and Ghibelline factions until the Visconti took control in 1277. Francesco Sforza married the daughter of the last male of the Visconti line, and effectively took over in 1447.