Škofja Loka was walled in the 14th century. In 1457, Duke Jan Vitovec entered and burned the town. The town was attacked by the Ottomans in 1476. The town also suffered from plague and fires during this time. Peasant revolts occurred in Škofja Loka in 1488, 1492, and 1515. Škofja Loka was destroyed by the 1511 Idrija earthquake but soon rebuilt through the efforts of Bishop Phillip. Lutheranism was established in Škofja Loka in 1526. Laws were passed against the new religion, and a Counter-Reformation committee was convened at the castle in 1601, resulting in the burning of Protestant books.