[8] After capturing the town, the Ottomans invested heavily in maintaining the fortifications, and kept a strong military contingent, making Kostajnica – alongside Bihać – their most important stronghold in the area.
The crushing Ottoman defeat in the Battle of Sisak in 1593, however, marked the turning point in the ongoing conflict, after which Kostajnica was no longer safe from recapture.
The attackers encountered heavily fortified defensive positions and – having no artillery and receiving news about incoming Ottoman reinforcements – decided to withdraw.
[10] Kostajnica was finally taken in 1688, by the army of Louis William, Margrave of Baden-Baden joined with the troops led by ban Nikola Erdödy.
The most popular spring Tekija has engraved sign (drink brother, potion was given to you by the god's mercy) “Pi brate iz Božje milosti dat ti je napitak.” In the late 19th and early 20th century, Kostajnica was a district capital in the Zagreb County of the Kingdom of Croatia-Slavonia.
During World War II, the town was occupied by Axis troops and was included into the Pavelić's Independent State of Croatia (NDH).
A large part of the Croatian population were expelled or killed by rebel Serbs in 1991 and the city was incorporated into the Republic of Serbian Krajina.
Houses and buildings belonging to Croats were burned and looted, including the baroque church, the medieval apothecary, and the eighteenth-century Franciscan monastery.
Kostajnica was put back in Croatian control following military victories by the army in August 1995, and the Croat population expelled slowly began returning.