The settlement of Kostanjevica was first mentioned as a town in 1210 and received market rights in 1249. During the Late Middle Ages it was an important commercial centre in the Duchy of Carniola held by the Habsburg archdukes of Austria. After several devastations by Ottoman military raids in the 15th and 16th centuries, it lost its importance. After the 17th century, it turned into a mostly rural settlement, which however retained its town status. In 2000, it was recognised by the National Assembly as a city.