
Scotland's finance secretary has quit hours before delivering his budget over claims he messaged a 16-year-old boy on social media.
The Scottish Sun reported that Derek Mackay contacted the boy over a six-month period, and told him that he was "cute".
Mr Mackay said he had "behaved foolishly" and took full responsibility for his actions.
And he apologised "unreservedly" to the boy and his family.
First Minister Nicola Sturgeon said she had accepted Mr Mackay's resignation, adding: "Derek has made a significant contribution to government, however he recognises that his behaviour has failed to meet the standards required."
The newspaper detailed allegations that the 42-year-old politician contacted the boy "out of the blue" and sent about 270 messages on Instagram and through Facebook.
It has published a list of conversations involving Mr Mackay and the boy, in which its says the SNP MSP invited him to dinner and to attend a rugby event.
In one of the exchanges it is claimed that Mr Mackay told the teenager he was "cute". In another the boy confirmed he was 16 and tells Mr Mackay "not to try anything".
The paper also quotes the boy's mother calling for Mr Mackay to be removed from his post.
In a statement released on Thursday morning, Mr Mackay said: "I take full responsibility for my actions. I have behaved foolishly and I am truly sorry. I apologise unreservedly to the individual involved and his family.
"I spoke last night with the first minister and tendered my resignation with immediate effect.
"Serving in government has been a huge privilege and I am sorry to have let colleagues and supporters down."
Derek Mackay's resignation cuts short what was a meteoric rise through Scottish politics.
He was elected a councillor in Renfrewshire in 1999 at the age of 21, and went on to lead the council for four years.
He became MSP for Renfrewshire North and West in 2011 and was made local government minister by Alex Salmond later that year.
When Nicola Sturgeon took office in 2015, he became transport minister, before being promoted to finance secretary following the 2016 Holyrood election. Many bookmakers had him down as the favourite to succeed Ms Sturgeon as first minister.
The 42-year-old was also a major figure in the SNP, serving as business convener for seven years, a role which saw him overseeing management of the party and chairing conferences and election campaigns.
Mr Mackay, who has been widely tipped as a future first minister, came out as gay when he left his wife in 2013.
His resignation came just hours before he was due to present the Scottish government's spending plans for the next year - a major set piece event in the Scottish Parliament.
Mr Mackay would have been putting the finishing touches to his preparations to his budget when he was contacted by the Scottish Sun on Wednesday evening, before the newspaper released the story at 23:20.
The budget will now be presented by the public finance minister, Kate Forbes.