Chris Tabraham became the youngest such inspector in the UK when he joined the organisation aged 21.
He had inspected every one of Historic Scotland's 345 sites, with the exception of Eagle Rock near Cramond. Friends and colleagues gathered at the site to wish him well in the future and present him with the camera he was given on his first day in the job in 1970.
Mr Tabraham said: "It has been a privilege to have a job which has enabled me to travel all around Scotland and meet so many interesting people."
He will spend his retirement researching the history of the 17th-century Ulster Scots.