Known since the 15th century in the Grand Duchy of Lithuania as the center of the volost of the same name. At the beginning of the 16th century, it belonged to Albrecht Gashtol'd. After the death of his son Stanislav in 1542 the city passed to the widow of the latter, Barbara Radziwill, who in 1547 married the heir to the Polish throne, bringing to him the numerous possessions of the Gashtol'ds. On April 10, 1572, Sigismund II Augustus transferred the town to the castellan of Vilna, Jan Ieronimovich Chodkevich. His son, the hetman, the great Lithuanian Jan Karol Khodkevich, built there in place of a small wooden castle a new stone castle of bastion type according to the most modern European models of that time. The castle was repeatedly unsuccessfully besieged by Ukrainian Cossacks and insurgent peasants. In 1635, the castle and the city passed into the possession of Jan Stanislaw Sapieha.
