In 1334, a watchtower was established on the Łyna River. In 1346, the forest was cleared at the location for a new settlement, mentioned in a historical document from 1348. The following year, Teutonic Knights began the construction of an Ordensburg castle as a stronghold against the Baltic Prussians. Allenstein was granted municipal rights by the cathedral chapter of the Bishopric of Warmia in October 1353. The German "Allenstein" referred to the river's Baltic Prussian name "Alna", which meant a hind. Local Poles, having arrived along with German settlers, called it "Holstin" and "Olsztyn", which are Polonizations of the German name. The castle was completed in 1397. The town 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.