The first mention of the town comes from 1283, during which the town was the property of the Masovian Dukes, and it got its city laws (Chełm law) in 1430. The greatest development of the city came during the 15th and 16th centuries. The Swedish Deluge brought an end to the prosperity of the city as much of it was destroyed. During both the January and November Uprising against Russia, the area was witness to battles against Russian forces. As a result of persecutions by the Tsarist regime, the city was deprived of its city rights in 1870, and two Russian regiments of infantry were stationed in the town. Throughout World War I the area again faced much destruction. The Polish 1st Legion's Infantry Regiment under the command of Edward Rydz-Śmigły was stationed in the town during 1917. After Poland regained its independence, city rights were restored in 1919. During the inter-war years the city was linked to the military: the 71st Infantry Regiment was stationed there and the town was home to a military school.