There has been a castle on this site since the late C12th, and between then and 1400 several versions of the castle were built and destroyed. Most of the remaining, but ruined, buildings here date from about 1400 when it was rebuilt by Bishop Walter Trail. Throughout the Middle Ages, St Andrews Castle was the official residence of Scotland’s leading bishop - later archbishop.
1546 saw probably the most dramatic series of events in the castle's history. The incumbent archbishop David Beaton imprisoned the protestant preacher George Wishart, then had him burnt at the stake outside the castle's walls. Wishart's friends and supporters then gained access to the castle and killed Beaton and hung his body out of a window at the front of the castle.
The castle continued to be the venue for strife between Catholics and Protestants over the next hundred years.
By 1656 the castle was in a dilapidated state and much of its stone was quarried to repair the town's pier.
One of its most interesting features is the mine and counter-mine that run under the surviving southern façade. The narrow cramped tunnels were built during sieges of the castle and can be visited, though you either have to stoop or crawl if you are more than about 3' tall! They are also not for the claustrophobic!
The castle is now in the care of Historic Scotland Link