Denbigh castle was built by Henry de Lacy, Earl of Lincoln as part of a borough-town foundation under license from King Edward Ist. Begun in 1282, it is likely that the first phase, which enclosed the southern and western sides of the castle and continued to define the boundary of the associated town, was complete by 1294. In around 1295 the N and W sides were constructed, thereby dividing the castle proper off from the town; this second phase is likely to have been completed by 1311. This later work, which includes the extraordinary gatehouse and a series of complex mantlets with postern gate and western sallyport, is regarded as one of the most accomplished pieces of contemporary military architecture in Wales and is almost certainly the work of Master James of St. George, Edward Ist's famous Savoyard master mason. Indeed, the sophistication of the gatehouse block exceeds anything attempted at Caernarvon, Conwy or Harlech.
In 1294, when the castle was still under construction, it fell to Madog ap Llewelyn in a widespread Welsh uprising known as Madog's Rebellion. This was clearly the inspiration for the more sophisticated building programme (which included the heightening of the existing walls) implemented in the following year. Earl Henry's son and heir, Edmund de Lacy, is said to have fallen to his death in the Denbigh castle well in 1308; the earl himself died in 1311. During the Glyndwr rebellion the castle was held for the crown and was not taken. During the Wars of the Roses, however, the castle was a major Yorkist centre. It was consequently subjected to frequent harrying by Lancastrian forces under Jasper Tudor, Earl of Pembroke, who in 1468, together with Dafydd ap Siencyn (the 'Welsh Robin Hood'), launched a failed assault on the castle, though managed to burn the town and suburbs.
During the Civil War the castle and old town were garrisoned and defended for the king by Colonel William Salesbury, a redoubtable commander nick-named 'Hen Hosanau Gleision ('Old blue stockings'). The famous siege of Denbigh under the parliamentarian generals Middleton and Mytton lasted for some nine months, during which time 'brave Denbigh' valiantly held out to much royalist acclaim (a contemporary poem describes the 'palace of Dame Loyalltie...surrounded closely with a narrow sea of black rebellion'). King Charles had visited Salesbury at Denbigh in September 1645, staying for three days in what became known as the King's Tower. As a consequence of this, Salesbury resolved to hold the castle at all costs with his five-hundred-strong garrison. When Denbigh finally capitulated on 26th October 1646 (on very favourable terms), it was only after the king had personally ordered Salesbury to do so; it was the last major main-land fortress in Britain to fall.
Following the surrender the castle was used as a prison for captured royalists, during which time it was twice attacked by forces under Major Dolben and Captain Chambres, who attempted to take back the fortress and release the captives. The castle was finally slighted in 1660 and was subsequently used as an (informal) quarry.