Around the late 12th century, it was a feudal sub-principality of the Russian principality of Polotsk. At the beginning of the 13th century, the German crusaders of the Order of the Brothers of the Sword under the leadership of Albert von Buxhövden began to occupy the coasts of the Bay of Riga.
Albert of Buxhövden ordered the construction of a brick castle to replace the wooden fortifications of the Latvians at the confluence of the Düna and Pērse rivers.
In 1420, Kokenhusen Castle became the summer residence of the Archbishops of Riga and their headquarters in the 16th century.
After destruction in the 17th century, the town became part of the Swedish possessions in 1629 and was fortified again. After further years of war, the town and castle were almost completely abandoned in 1684.