The Duchy was created in 1395 for Gian Galeazzo Visconti, Lord of Milan. When the Visconti became extinct in 1447, Milan declared itself a republic, despite the fact that the Duke of Orleans was the legitimate heir by treaty. Orleans proved unable to make good his claim, but the republic was nevertheless short-lived. The adventurer Francesco Sforza, who married the last Visconti's illegitimate daughter, seized Milan in 1450 and made himself Duke.
In 1498 the Duke of Orleans became King of France as Louis XII, and immediately sought to make good his father's claims to Milan. He invaded in 1499 and soon ousted Lodovico Sforza. The French ruled the Duchy until 1513, when they were ousted by the Swiss, who put Lodovico's son Massimiliano on the throne. Massimiliano did not last very long. The French, now under Francis I, again invaded in 1515 and reasserted their control at the Battle of Marignano, and making Massimiliano their prisoner. The French were again driven out in 1521, this time by the Spanish, who installed Massimiliano's younger brother, Francesco II Sforza.
Following the decisive French defeat at Pavia in 1525, which seemed to leave the Imperial forces of Charles V dominant in Italy, Francesco joined the League of Cognac against the Emperor along with Venice, Florence the Pope, and the French. This resulted quickly in his own expulsion from Milan by Imperial forces, but he managed to remain in control of various other cities in the Duchy, and was again restored to Milan itself by the peace concluded at Cambrai in 1529.
When Francesco died without heirs in 1535, the question of succession again arose, with both the Emperor and the King of France claiming the Duchy, leading to more wars. The Emperor held the Duchy throughout, eventually investing it on his son Philip. The possession of the Duchy by Spain was finally recognized by the French in the Treaty of Cateau-Cambrésis in 1559.
The Duchy of Milan remained in Spanish hands until the War of the Spanish Succession in the early 18th century, when it was conquered by the Austrians. The Treaty of Baden which ended the war in 1714 ceded Milan to Austria. The Duchy remained in Austrian hands until it was overrun by the French army of Napoleon Bonaparte in 1796. The Duchy was ceded by Austria in the Treaty of Campo Formio in 1797, and formed the central part of the new Cisalpine Republic.