Derek Mackay's downfall: How the story unfolded
It has been a turbulent week at Holyrood, as Derek Mackay quit as Scotland's finance secretary hours before he was due to deliver the Scottish government's budget.
His dramatic fall from grace came after a newspaper revealed that the SNP MSP sent 270 messages to a 16-year-old schoolboy over six months.
This is how the scandal unfolded:
August 2019 - Feb 2020
Derek Mackay sends private messages to the teenager via Facebook and Instagram, according to a transcript published by The Scottish Sun.
He repeatedly messages the boy, even when the child fails to respond.
In September, he asks: "What age are you btw?" The boy tells him he is 16. Mr Mackay replies: "Oh right".
The minister asks him to help deliver leaflets and invites him to a rugby reception at the Scottish Parliament.
In December, he tells the boy he thinks he is "really cute". Following that remark, he sends a further eight messages, but the boy does not respond.
1 - 2 Feb
The Scottish Sun finds out that Derek Mackay has been messaging the teenager. The paper's political editor told the BBC's Podlitical podcast that the paper was contacted by the teenager's mother at the weekend, who only found out about the messages the previous week.
5 Feb
10:00: Derek Mackay has a photo opportunity planting trees in Fife ahead of unveiling his budget. He does not know that the journalists have learned of the messages to the teenager.
17:50: The Scottish Sun's editor contacts Nicola Sturgeon's spokesman and details the story to him. The editor asks for a response from the Scottish government.
18:20: Derek Mackay returns to the chamber, followed by Ms Sturgeon a few minutes later. The Scottish Sun's political editor says both the parliamentarians knew about the allegations at this stage.
19:23: The Scottish government emailed The Scottish Sun's journalists to demand "full evidence" and "justification" for intruding into Mr Mackay's private life. The paper declined.
Allow Twitter content?
21:22: The Scottish government tells the paper it will not comment on the story.
23:00: The Scottish Sun publishes the story on its website and the paper goes to print.
6 Feb
08:09: The Scottish government releases a statement. Mr Mackay said he had "behaved foolishly" and took full responsibility for his actions.
He apologised "unreservedly" to the boy and his family. The statement also revealed that the first minister had accepted his resignation from the cabinet.
12:00: Nicola Sturgeon addresses MSPs and confirms that Mr Mackay has resigned as finance secretary.
She also confirms that he has been suspended by the SNP while further investigations are carried out.
14:50: The Scottish government's budget is delivered by Public Finance Minister Kate Forbes.
7 Feb
Further newspaper allegations about Mr Mackay's behaviour are published.
The Daily Record reveals it has spoken to a married SNP activist who claims he was "bombarded" by unwanted messages from Mr Mackay for four years - including one that asked: "Got any naughty pics?"
And The Herald claimed that Mr Mackay, 42, was banned by First Minister Nicola Sturgeon from drinking during SNP conferences because of concerns over his behaviour.
Deputy First Minister John Swinney defends the government's handling of the scandal during an interview on BBC Radio's Good Morning Scotland programme.