Settlement at Kežmarok dates back to the Upper Stone Age. In the 13th century the region contained a community of Saxons, a Slovak fishing village, a Hungarian border post and a Carpathian German settlement. Its Latin name was first mentioned in 1251 as Villa (Saxonum apud Ecclesiam) Sancte Elisabeth. In 1269 Kežmarok received its town charter. It also had the right to organize a cheese market (hence the German name Kesmark ("Käsemarkt" - "cheese market"). In 1433 the town was severely damaged by a Hussite raid. After 1440, the count of Spiš had a seat in Kežmarok. In the 15th century (and then once more in 1655), Kežmarok became a free royal town.
The town's monuments include a castle, many Renaissance merchant houses, and a museum of ancient books. In pride of place is the Protestant church built in 1688 entirely of wood. The church also contains an organ of 1719 with wooden pipes. The church has been a UNESCO World Heritage Site since 2008.
Kežmarok had an ethnic German majority until around 1910, and Germans stayed a large minority until the end of World War II. It also had a large and active Jewish community. During World War II, under the auspices of the First Slovak Republic, nearly 3,000 of the town's Jews were deported to German death camps. The town's pre-war Jewish cemetery has now been restored.