Elgin (pronounced /ˈɛlɡɪn/; Scottish Gaelic: Eilginn) is a old cathedral city and Royal Burgh in Moray, Scotland. The town was first to the south of the River Lossie on the higher ground above the flood plain. Elgin is first documented in the Cartulary of Moray in 1190.
In August 1040, Macbeth's army beat Duncan I at Bothganowan (Pitgaveny), near Elgin. David I made Elgin a royal burgh around 1130, after his defeat of Óengus of Moray. During David's reign, the castle was built at the top of what is now Lady Hill. Edward I of England travelled twice to Elgin. During his first visit in 1296 he was impressed by what he saw. In the 19th century the old medieval town of Elgin was swept away, and many new buildings were added to the town centre.