Craigmillar Castle construction began in the late 14th century by the Preston clan, Barons of Craigmillar, and extensions were made in the 15th and 16th centuries. In 1660 the castle has been sold to Sir John Gilmour, President of the Court of Session, who carried out alterations. The Gilmours left Craigmillar in the 18th century, and the castle fell into disrepair. Historic Scotland now maintains it.
Craigmillar Castle is famous for its association with Mary, Queen of Scots. Following her illness after her son's birth, the future James I of England, Mary arrived at Craigmillar on 20 November 1566 to convalesce. Before leaving on 7 December 1566, a pact known as the 'Craigmillar engagement' was made, with or without her knowledge, to get rid of her husband Henry Stuart, Lord Darnley.
Craigmillar is one of the best-preserved medieval castles in Scotland. The central tower house, or keep, is surrounded by a 15th-century wall with 'particularly elaborate' defensive features. Within the courtyard bounded by this wall are other buildings. Outside the wall is a second courtyard containing a chapel and a dovecote, surrounded by a double border.