Human settlements in Kostajnica area are known as early as from the period of ‘Vučedol culture’ and afterwards from bronze and iron age. According to the remains found and documents preserved from the Roman times, commercial traffic was present across Una River. Thanks to such position, Kostajnica was even then a significant settlement with a Roman aqueduct built.
The name Kostajnica was first mentioned in 1258. In the Middle Ages, Kostajnica was a part of the Kingdom of Hungary i.e. in possession of nobility which recognized the Hungarian crown. After 1513 (the victory of the Turks near Dubica) masters (the Ottomans and Austro-Hungarian Empire) were changing in constant warfare. There were lots of rebellions of the local population during the Ottoman rule. The most famous rebellion is Pecija’s rebellion of 1858, raised by hajduks Petar Petrović Pecija and Petar Garača.