Sir John Eldvidge, the Scottish government's top civil servant, has announced he is to retire.
Sir John, who has been permanent secretary to the government for seven years, will leave his post next month.
He said: "It has been a hugely stimulating and enjoyable role."
He will be replaced by Peter Housden, currently permanent secretary to the Department of Communities and Local Government within the UK government.
Sir John said: "It is a difficult job to leave but it calls for someone who can provide continuity of leadership before and after the Scottish elections next year and in supporting ministers in planning and delivering the response to the public expenditure changes which lie ahead.
"I am proud of the way in which the civil service has adapted to the continuing development of devolution.
"I am confident that I am leaving behind an organisation well placed to tackle the challenges of the future.
The First Minister, Alex Salmond, said: "I have thoroughly enjoyed working with John Elvidge.
"He merits enormous credit for the professionalism with which the civil service supported the change of government in 2007 and has worked with me and my ministerial team since then to make a success of Scotland's experience of minority government.
"I fully understand his decision to stand down after seven years in the role, in order to ensure continuity of leadership for the civil service over the period before and after the Scottish elections next May."
The head of the civil service, Sir Gus O'Donnell said Sir John has "been an excellent and loyal permanent secretary, and I'm grateful for all he has done in Scotland, in particular, his support to two Scottish governments through seven years of Scotland's development of devolution."