Scotland’s Finance Secretary Derek Mackay resigned Thursday, just hours before he was set to deliver the annual budget, following reports that he sent hundreds of messages to a 16-year-old boy he befriended on social media back in early August.

The 42-year-old finance minister issued a statement announcing the immediate resignation from his post, as well as an apology to the teen to whom he reportedly sent more than 270 messages on Facebook and Instagram as recently as five days ago, The Scottish Sun reported.

UK WOMAN WHO JUMPED FROM CHINA APARTMENT LEFT PHONE PASSWORDS TO SUICIDE NOTE, INQUEST FINDS

"I take full responsibility for my actions. I have behaved foolishly and I am truly sorry,” Mackay’s statement read. “I apologize unreservedly to the individual involved and his family. I spoke last night to the First Minister and tendered my resignation with immediate effect.”

According to the report, Mackay first reached out to the teen on Aug. 2 in a private online message sent on Instagram. Over the next six months, the politician engaged in several conversations with the boy, including one exchange where he asked if their “chats” were “between us?”

The messages seen by The Sun appear to show that Mackay was well aware of the boy’s age.

On one occasion in September, he invited the 16-year-old to a rugby game, offering to pay for the tickets. Then in December, he again invited him to another rugby function being held in Holyrood. Mackay also tried to enlist the teen’s help in handing out leaflets for his campaign.

GERMAN WOMAN USES TINDER TO FIND HELP AFTER GETTING STUCK AT EUROPE’S MOST NORTHERN POINT

The teen told the outlet that he stopped answering Mackay after he sent him a message on Dec. 27 calling him “cute.” He received two messages since, with the most recent being sent last week.

The boy’s mother also spoke to The Sun and said she only recently found out about Mackay’s texting relationship with her son.

“A man like that is not supposed to say these sort of things to a boy — he looks like he wants something from my son. When I finally read the messages it was terrifying and made my stomach turn,” she said.

CLICK HERE TO GET THE FOX NEWS APP

Mackay, who has not been accused of breaking the law, was a rising star in the Scottish National Party, which runs Scotland’s semi-autonomous Edinburgh-based administration. He had been seen as a potential successor to First Minister Nicola Sturgeon as leader of the SNP, which advocates independence from the United Kingdom for the nation of 5.5 million.

"Serving in government has been a huge privilege and I am sorry to have let colleagues and supporters down,” Mackay said in a statement.

Sturgeon said in a statement that Mackay has also been suspended from the SNP.

"I don't condone in any way, shape of form this kind of behavior," Stugeron said.

The Associated Press contributed to this report.