<p>Scotland's finance secretary Derek Mackay quit just hours before he was due to present the budget on Thursday, saying he had "behaved foolishly" in a string of messages to a 16-year-old schoolboy.</p>.<p>The 42-year-old apologised to the teenager and First Minister Nicola Sturgeon accepted his resignation.</p>.<p>Mackay suddenly stepped down shortly before he was set to unveil the Scottish government's budget for the next financial year, after a newspaper exposed his messages.</p>.<p>The Scottish Sun reported that he had befriended the schoolboy on Facebook and Instagram and sent him 270 social media messages over a six-month period.</p>.<p>In one message he is alleged to have asked: "And our chats are between us?" and when the boy agreed, told him: "Cool, then to be honest I think you are really cute."</p>.<p>The tabloid said Mackay offered to take him out to dinner and a rugby game.</p>.<p>"I take full responsibility for my actions. I have behaved foolishly and I am truly sorry," Mackay said in a statement.</p>.<p>"I apologise unreservedly to the individual involved and his family.</p>.<p>"I spoke last night with the first minister and tendered my resignation with immediate effect.</p>.<p>"Serving in government has been a huge privilege and I am sorry to have let colleagues and supporters down."</p>.<p>Mackay had been the finance minister since 2016. He was seen as a rising star of Scottish politics.</p>.<p>The father-of-two announced in 2013 that he had separated from his wife, adding that it was "important for me to be clear publicly that I am gay".</p>.<p>The Scottish budget will now be presented by junior public finance minister Kate Forbes, 29.</p>.<p>Within the United Kingdom, Scotland has its own devolved parliament, with its government deciding policy and spending on areas such as health and education.</p>.<p>The left-wing, secessionist Scottish National Party runs a minority administration in Edinburgh, and is pushing for a second referendum on Scottish independence.</p>.<p>In accepting his resignation, SNP leader Sturgeon said Mackay "recognises that his behaviour has failed to meet the standards required".</p>.<p>The Scottish Sun published full threads of messages dating from August 2 last year until February 1.</p>.<p>Mackay contacted the boy out of the blue and asked what age he was, saying "oh right" after being told he was 16.</p>.<p>The teenager's mother, 37, learned of the exchanges last week.</p>.<p>"If I could speak to him, I would ask him 'Why? Why did you do this?'," she told the Scottish Sun.</p>.<p>"You can see he tries again and again -- like he is trying to get my son to change his mind about something.</p>.<p>"He is trying to see how much he can push it."</p>.<p>Murdo Fraser, finance spokesman for the main opposition Conservatives in the Scottish Parliament, said Mackay was popular across the chamber.</p>.<p>"This is, however, a huge blow for Nicola Sturgeon to lose such a key member of her government at such a crucial time -- and one tipped as her successor."</p>
<p>Scotland's finance secretary Derek Mackay quit just hours before he was due to present the budget on Thursday, saying he had "behaved foolishly" in a string of messages to a 16-year-old schoolboy.</p>.<p>The 42-year-old apologised to the teenager and First Minister Nicola Sturgeon accepted his resignation.</p>.<p>Mackay suddenly stepped down shortly before he was set to unveil the Scottish government's budget for the next financial year, after a newspaper exposed his messages.</p>.<p>The Scottish Sun reported that he had befriended the schoolboy on Facebook and Instagram and sent him 270 social media messages over a six-month period.</p>.<p>In one message he is alleged to have asked: "And our chats are between us?" and when the boy agreed, told him: "Cool, then to be honest I think you are really cute."</p>.<p>The tabloid said Mackay offered to take him out to dinner and a rugby game.</p>.<p>"I take full responsibility for my actions. I have behaved foolishly and I am truly sorry," Mackay said in a statement.</p>.<p>"I apologise unreservedly to the individual involved and his family.</p>.<p>"I spoke last night with the first minister and tendered my resignation with immediate effect.</p>.<p>"Serving in government has been a huge privilege and I am sorry to have let colleagues and supporters down."</p>.<p>Mackay had been the finance minister since 2016. He was seen as a rising star of Scottish politics.</p>.<p>The father-of-two announced in 2013 that he had separated from his wife, adding that it was "important for me to be clear publicly that I am gay".</p>.<p>The Scottish budget will now be presented by junior public finance minister Kate Forbes, 29.</p>.<p>Within the United Kingdom, Scotland has its own devolved parliament, with its government deciding policy and spending on areas such as health and education.</p>.<p>The left-wing, secessionist Scottish National Party runs a minority administration in Edinburgh, and is pushing for a second referendum on Scottish independence.</p>.<p>In accepting his resignation, SNP leader Sturgeon said Mackay "recognises that his behaviour has failed to meet the standards required".</p>.<p>The Scottish Sun published full threads of messages dating from August 2 last year until February 1.</p>.<p>Mackay contacted the boy out of the blue and asked what age he was, saying "oh right" after being told he was 16.</p>.<p>The teenager's mother, 37, learned of the exchanges last week.</p>.<p>"If I could speak to him, I would ask him 'Why? Why did you do this?'," she told the Scottish Sun.</p>.<p>"You can see he tries again and again -- like he is trying to get my son to change his mind about something.</p>.<p>"He is trying to see how much he can push it."</p>.<p>Murdo Fraser, finance spokesman for the main opposition Conservatives in the Scottish Parliament, said Mackay was popular across the chamber.</p>.<p>"This is, however, a huge blow for Nicola Sturgeon to lose such a key member of her government at such a crucial time -- and one tipped as her successor."</p>