In 1448, King Casimir IV Jagiellon granted it Magdeburg rights town charter, together with a privilege to organize fairs, which spurred Olsztyn's development.
In 1807 it was regained by Poles and included within the short-lived Polish Duchy of Warsaw, and after its dissolution in 1815, Olsztyn belonged to Russian-controlled Congress Poland.
After the joint German-Soviet invasion of Poland, which started World War II in September 1939, Olsztyn was occupied by Germany until 1945.
The Germans used local forests to carry out executions of inhabitants of Częstochowa and Radomsko, and captured Home Army soldiers, prisoners of war and villagers (see Nazi crimes against the Polish nation).
After the Warsaw Uprising, in October 1944, the Germans deported 1,800 Varsovians from the Dulag 121 camp in Pruszków, where they were initially imprisoned, to Olsztyn.
This led to barn burning and a large cull of horses in the area, which made the wandering Romany Gypsies easy targets for the oncoming Germans.