In 1226 Emperor Frederick II declared the city of Lübeck to be an Imperial Free City. In the 14th century Lübeck became the "Queen of the Hanseatic League", being by far the largest and most powerful member of this medieval trade organization.
Several conflicts about trade privileges were fought by Lübeck and the Hanseatic League against Denmark with varying outcomes. While Lübeck and the Hanseatic League prevailed in conflicts in 1435 and 1512, Lübeck lost when it became involved in the Count's Feud, a civil war that raged in Denmark from 1534 to 1536. Lübeck also joined the Schmalkaldic League. After defeat in Count's Feud, Lübeck's power slowly declined. Lübeck managed to remain neutral in the Thirty Years' War, but with the devastation of the decades-long war and the new transatlantic orientation of European trade, the Hanseatic League and thus Lübeck lost importance. After the Hanseatic League was de facto disbanded in 1669, Lübeck stayed an important trading town on the Baltic Sea.
In 1937 the Nazis passed the so-called Greater Hamburg Act, where the nearby Free and Hanseatic City of Hamburg was expanded, to encompass towns that had formally belonged to the Prussian province of Schleswig-Holstein. To compensate Prussia for these losses (and partly because Hitler had a personal dislike for Lübeck), the 711-year-long independence of Lübeck came to an end and almost all its territory was incorporated into Schleswig-Holstein.