The first written mention is from 997, when a biography of Saint Adalbert records his visit to a town called Gyddanyzc, ruled by the Polish duke Bolesław I the Brave. Archaeologists have found a 10th century stronghold in what is now the Góra Gradowa district. Pomeranian fishermen and craftsmen lived here first. Later, German settlers arrived, mostly from Lübeck, and by 1263 the town had Lübeck-law rights.
In 1308 the Teutonic Knights massacred Brandenburg's troops and the Pomeranian knights backing them, and townspeople too. Estimates of the dead run from about 60 to about 1,000. Rebuilding began only in the mid-1320s. A castle went up in 1340, and in 1358 the town joined the Hanseatic League. Grain, timber and potash coming down the Vistula made it wealthy.
In 1454 the city turned against the Knights and asked the Polish king to take it back. Three years later the Great Privilege gave it self-rule, its own coin and freedom from tariffs on trade within Poland. New Town, which had sided with the Knights, was torn down so completely that no buildings were left. Gdańsk was the largest city in Poland and one of the most influential, with a vote in royal elections. In 1577 it refused to recognise a newly elected king, Stephen Báthory, and endured a six-month siege. Its army of 5,000 mercenaries was beaten in the field, and the city then recognised him and paid 200,000 gold guldens as an apology.
The 1600s brought war with Sweden. In 1627 ships fought the Battle of Oliwa close to the city, and the Treaty of Oliwa ended a later war in 1660. Around 1640 Johannes Hevelius set up his observatory in the Old Town. Plague and a slow economic decline set in. The city remained part of Poland as an exclave cut off from the rest of the country, and in 1793 Prussia annexed it. The councillor Johann Uphagen resigned in protest.
In 1871 the city built a sewer system with wastewater treatment, the first of its kind on the Continent. After the First World War it became the Free City of Danzig, under the League of Nations, with its own constitution, stamps and currency. Poland kept a garrison at Westerplatte and a post office in the city. In the 1930s the local Nazi party under Albert Forster won the city's elections. On 1 September 1939 the first shots of the Second World War were fired at Westerplatte, and a few men held the Polish post office for hours before they were executed.
Polish and Soviet troops took the city in March 1945, and it was heavily damaged. About 124,000 Germans were still there in June, and the Polish authorities began deporting them the next month. Poles moved in, up to 18 percent of them deported by the Soviets from pre-war eastern Poland. Parts of the old city were rebuilt in the 1950s and 1960s, with Flemish, Dutch, Italian and French influences stressed to play down the German one. That is why the buildings you see today differ in style from the ones before the war.
Under communism Gdańsk became a major shipping and industrial centre. In 1970 troops and police fired on protesters here, killing several dozen people. Ten years later the shipyard gave birth to Solidarity, whose leader Lech Wałęsa became president in 1990. In January 2019 the mayor, Paweł Adamowicz, was assassinated; in October the city won the Princess of Asturias Award. Donald Tusk, who was born in Gdańsk, has been Polish prime minister since 2023.