LONDON — The finance secretary of Scotland resigned abruptly, hours after British news outlets revealed that he had sent suggestive messages to a 16-year-old boy on social media, the Scottish government confirmed on Thursday.

The finance secretary, Derek Mackay, 42, is reported to have sent the boy hundreds of messages, beginning last August and continuing into this month, according to The Scottish Sun. Those messages included telling the boy he was “really cute” and inviting him to attend a rugby match with him.

Mr. Mackay, who was seen as a rising star in the Scottish National Party, said in a statement that he had tendered his resignation to the head of the Scottish government, Nicola Sturgeon, late Wednesday and apologized “unreservedly” to the boy and his family.

“I take full responsibility for my actions,” he said. “I have behaved foolishly, and I am truly sorry.”