Dr Catherine Calderwood agreed to step down just hours after “unreservedly” apologising for the trip to Fife and withdrawing from public briefings.
She said that she took the decision following a discussion with first minister Nicola Sturgeon, who said that the issue “risks undermining confidence” in the government’s advice.
“I am deeply sorry for my actions and the mistakes I have made,” Dr Calderwood said in a statement.
“The first minister and I have had a further conversation this evening and we have agreed that the justifiable focus on my behaviour risks becoming a distraction from the hugely important job that government and the medical profession has to do in getting the country through this coronavirus pandemic.
“Having worked so hard on the government’s response, that is the last thing I want. The most important thing to me now and over the next few very difficult months is that people across Scotland know what they need to do to reduce the spread of this virus and that means they must have complete trust in those who give them advice.
“It is with a heavy heart that I resign as Chief Medical Officer. I will work with my team over the next few days to ensure a smooth transition to my successor.”