Scotland's Finance Secretary Derek Mackay has been suspended by the SNP party, after allegations emerged that he sent hundreds of messages to a 16-year-old boy.
Mr Mackay resigned just hours before he was due to unveil the Scottish Government's budget for the next financial year and it will now be presented by public finance minister Kate Forbes.
The father-of-two befriended the teenager on Facebook and Instagram and sent him 270 social media messages, the Scottish Sun reported.
Mr Mackay said in a statement he takes "full responsibility" for his actions.
"I have behaved foolishly and I am truly sorry," the finance secretary said. "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 Mr Mackay's resignation and said he had made "a significant contribution to government."
"However he recognises that his behaviour has failed to meet the standards required," Ms Sturgeon added.
The Sun published a long string of messages allegedly sent to the boy by the Renfrewshire North and West MSP.
In one message he is alleged to have asked “And our chats are between us?” and when the boy agrees told him: “Cool, then to be honest I think you are really cute.”
The newspaper alleges he contacted the teenager over a six-month period, and offered to take him to a rugby game and out to dinner.
In one of the messages the boy tells Mr Mackay he is 16.
Before Mr Mackay's resignation, the teenager’s mother called Nicola Sturgeon to act, telling The Sun: “A man like that is not supposed to say these sort of things to a boy.”
In 2017, then childcare minister Mark McDonald quit the Scottish Government after an investigation by the SNP accused him of "inappropriate behaviour", which was said to include the sending of inappropriate and unwanted text and social media messages.
MSP Murdo Fraser said on Twitter that the resignation of Scotland's FinanceSecretary Derek Mackay will be a "huge blow" for Nicola Sturgeon.
He wrote: "Derek MacKay acted foolishly and is right to resign from the Govt.Politics aside, I have always enjoyed working with him, and he is popular in his own Party and across the Parliament. I wish him and his family well in what will be a difficult time.
"This is, however, a huge blow for Nicola Sturgeon to lose such a key member of her Govt at such a crucial time - and one tipped as her successor."