Olsztyn (; Old Polish: Holstin; Old Prussian: Alnāsteini or Alnestabs; ) is a city on the Łyna River in northeastern Poland. Olsztyn is the capital of the Warmian-Masurian Voivodeship, and is a city with powiat rights.
In 1346, on Warmian land, the forest was cleared at a location on the Alle ( Alna river), now Łyna River, for a new settlement in Prussian Warmia. The following year, Teutonic Knights began the construction of an Ordensburg-type castle as a stronghold against the Old Prussians, and the settlement of Allenstein was first mentioned the following year. The German-language name Allenstein meant a castle on the Alle River, and the settlement became known in Polish-language transliteration as Olsztyn. The settlement received municipal rights from Johannes von Leysen on 31 October 1353, and the castle was completed in 1397. Allenstein was captured by the Kingdom of Poland during the Polish-Lithuanian-Teutonic War in 1410, and again in 1414 during the Hunger War, but it was returned to the monastic state of the Teutonic Knights after hostilities ended.
Allenstein joined the Prussian Confederation in 1440. It rebelled against the Teutonic Knights in 1454 upon the outbreak of the Thirteen Years' War and requested protection from the Polish Crown. Although the Teutonic Knights captured the town the following year, it was retaken by Polish troops in 1463. The Second Peace of Thorn in 1466 designated Allenstein and the Bishopric of Warmia as part of Royal Prussia under the sovereignty of the Crown of Poland.
From 1516 to 1521, Nicolaus Copernicus lived at the castle as administrator of both Allenstein and Mehlsack (now Pieniężno). Copernicus was in charge of the defenses of Allenstein and Warmia during the Polish-Teutonic War of 1519–21.
The town was annexed by the Kingdom of Prussia in 1772 during the First Partition of Poland. A Prussian census recorded a population of 1,770 people, predominantly farmers, and Allenstein was administered within the Province of East Prussia. It was visited by Napoleon Bonaparte in 1807 after his victories over the Prussian Army at Jena and Auerstedt. By 1825, the town was inhabited by 1266 Poles and 1341 Germans The German-language newspaper, Allensteiner Zeitung, was first published in 1841. The town hospital was founded in 1867.
Allenstein became part of the German Empire in 1871 during the Prussian-led unification of Germany. Two years later, the city was connected by railway to Thorn (Toruń). Its first Polish language newspaper, the Gazeta Olsztyńska, was founded in 1886. Allenstein's infrastructure developed rapidly: gas was installed in 1890, telephones in 1892, public water supply in 1898, and electricity in 1907. In 1905, the city became the capital of Regierungsbezirk Allenstein, a government administrative region in East Prussia. From 1818 to 1910, the city was administered within the East Prussia Allenstein District, after which it became an independent city.
Shortly after the outbreak of World War I, troops of the Russian Empire captured Allenstein in 1914, but it was recovered by the Imperial German Army in the Battle of Tannenberg. The battle actually took place much closer to Allenstein than to Tannenberg (now Stębark), but the victorious Germans, having been defeated in the medieval battle of Tannenberg, named it as such for propaganda purposes.
The football club SV Hindenburg Allenstein played in Allenstein from 1921 to 1945. After the Nazi seizure of power in 1933, Poles and Jews in Allenstein were increasingly persecuted. In 1935, the Wehrmacht made the city the seat of the Allenstein Militärische Bereich. It was the home of the 11th Infanterie Division, the 11th Artillery Regiment, and the 217th Infanterie Division.
On 12 October 1939, after the German invasion of Poland that began World War II, the Wehrmacht established an Area Headquarters for Wehrkreis I that controlled the sub-areas of Allenstein, Lötzen (now Giżycko) and Zichenau (now Ciechanów). Beginning in 1939, members of the Polish-speaking minority, especially members of the Union of Poles in Germany, were deported to German death camps.
Allenstein was plundered and burnt by the invading Soviet Red Army on 22 January 1945, as the Eastern Front reached the city. Allenstein's German population evacuated the region or were subsequently expelled. On 2 August 1945, the city became part of Poland according to the Potsdam Agreement, and officially renamed to the Polish Olsztyn. In October 1945, the German population of Olsztyn was expelled by Order of the City Commanders of Olsztyn.