The Cathedral of St Andrew was built in 1158 and became the centre of the Medieval Catholic Church in Scotland as the seat of the Archdiocese of St Andrews and the Bishops and Archbishops of St Andrews. It fell into disuse and ruin after Catholic mass was outlawed during the 16th-century Scottish Reformation. It is currently a monument in the custody of Historic Environment Scotland. The ruins indicate that the building was approximately 119 m long, and is the largest church to have been built in Scotland.
The west end was blown down in a storm and rebuilt between 1272 and 1279. The cathedral was finally completed in 1318 and featured a central tower and six turrets; of these remain two at the east and one of the two at the western extremity, rising to a height of 30 metres. On the 5th of July it was consecrated in the presence of King Robert I, who, according to legend, rode up the aisle on his horse.
A fire partly destroyed the building in 1378; restoration and further embellishment were completed in 1440.
In June 1559 during the Reformation, a Protestant mob incited by the preaching of John Knox ransacked the cathedral; the interior of the building was destroyed. The cathedral fell into decline following the attack and became a source of building material for the town. By 1561 it had been abandoned and left to fall into ruin.
References:The first written record of church in Danmark locality date back to the year 1291. Close to the church are several stones with a Christian text and cross inscribed. The oldest parts of the present red-brick church are from the 1300s. In the late 1400s the church was enlarged to the appearance it has today. The church has been modified both internally and externally several times, among other things after the fires in 1699 and 1889. There are lot of well-preserved mural paintings in the walls.