The locality was a site of the ancient Old Prussian settlement Twangste. In 1255, a new fortress was built on this site by the Teutonic Knights during the Northern Crusades, and was named "Königsberg" in honour of King Ottokar II of Bohemia. The town was part of the State of the Teutonic Order, the Polish-Lithuanian Commonwealth, Prussia and Germany. Until the end of World War II, the area formed the northern part of the former German East Prussia. The town was part of the Polish Zone of Occupation after the end of World War II, along with the rest of East Prussia, and was formally annexed by Poland in 1949. Most German inhabitants fled the city during the war.
According to the 2010 Census, its population was 573,765 — an increase from the 2002 Census. Its ethnic composition is 77.9% Poles, 8.0% Lithuanians, 7.3% Germans, 1.9% Belarusians, 0.6% Russians, and 0.5% Ukrainians.