Scotland's Finance Secretary has resigned hours before his own Budget after a newspaper published messages to a 16-year-old boy.
Derek Mackay, 42, said today he takes "full responsibility for my actions" adding: "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."
First Minister Nicola Sturgeon accepted the resignation of Mr Mackay - a rising star who had been tipped as her successor.
The Scottish Sun reported the Renfrewshire North and West MSP befriended a 16-year-old on Facebook and Instagram and sent him 270 social media messages over a six-month period.
A long string of alleged messages was published, apparently in full, by the newspaper in which he allegedly offered to take the teenager to a rugby game and out to dinner.
After months of contact, in one message he was alleged to have asked "And our chats are between us?". When the boy agreed he apparently told him: "Cool, then to be honest I think you are really cute."
It is claimed he then sent a dozen follow-up messages with no reply, other than a thumbs-up symbol that the teenager swiftly deleted.
The allegations emerged as Mr Mackay prepared to unveil the Scottish Government's Budget for the next financial year later today in Holyrood, Edinburgh.
In one of the messages the boy said he was 16. Before Mr Mackay's resignation this morning, the teenager's mother had called on First Minister Nicola Sturgeon to act.
She told the newspaper: "Nicola Sturgeon should remove him from his position. I don't know if he should lose his job but he should be dealt with very seriously."
In a statement this morning, Ms Sturgeon said: "Derek has taken full responsibility for his actions and apologises unreservedly for them to the individual involved and to those he has let down.
"He has submitted his resignation as a government minister which I have accepted.
"Derek has made a significant contribution to government, however he recognises that his behaviour has failed to meet the standards required.
"The Minister for Public Finance, Kate Forbes, will present today’s Scottish Government budget setting out our actions to support the economy, back our people and public services and tackle the climate crisis, and that remains my government's focus."
The former Renfrewshire Council leader was often tipped as a future SNP leader after leading the Scottish government's nationalisation rescue of the last commercial shipyard in the Clyde.
The father-of-two previously told how revealing he is gay was tougher than anything he had faced in politics. He came out after breaking the news to Jennifer, his wife of 12 years, in 2013.