Former Scottish National Party (SNP) leader Alex Salmond has resigned from the party amid allegations of sexual misconduct.
In a statement he said he wanted to avoid internal division within the SNP, which has faced calls to suspend him.
He has denied any wrongdoing, and said he intended to apply to rejoin once he had an opportunity to clear his name.
It emerged last week that two Scottish government staff members had lodged complaints in January about his behaviour when he was first minister, says a BBC report.
Salmond has described the allegations as "patently ridiculous" - and has also criticised the complaints procedure which he claims is "unjust".
On Tuesday he formally began legal action against the Scottish government in the Court of Session over its handling of the misconduct allegations.
In a statement released on social media, Salmond said he had been a member of the SNP for 45 years, 20 of them as party leader and seven as first minister.
He continued: "I truly love the SNP and the wider independence movement in Scotland. They have been the defining commitment of my life. But today I have written to the National Secretary of the party resigning my membership."
Salmond indicated that his resignation was to avoid potential divisions within the party, as his successor Nicola Sturgeon faced opposition calls to suspend his SNP membership.
He stated: "I did not come into politics to facilitate opposition attacks on the SNP and, with Parliament returning next week, I have tendered my resignation to remove this line of opposition attack.
"Most of all, I am conscious that if the party felt forced into suspending me it would cause substantial internal division."
The current SNP leader and first minister, Nicola Sturgeon, said she "felt a huge sadness about the whole situation".
In a statement on Twitter, she said the decision was Alex Salmond's alone, and she understood why he had chosen to separate "the current questions he is facing from the day to day business of the SNP and the ongoing campaign for independence".
She continued: "The hard fact remains that two complaints were received by the Scottish government that could not be ignored or swept under the carpet."
The Daily Record newspaper broke the news of the sexual misconduct allegations last Thursday.
The paper claims to have seen the wording of one complaint which describes an incident alleged to have taken place at the first minister's official residence in Edinburgh, Bute House, in the first week of December 2013.
The two women lodged complaints in January this year, just weeks after the Scottish government adopted a new complaints procedure in the light of wider concern about sexual harassment at Holyrood and Westminster.
Salmond claims that the subsequent investigation into the allegations against him by senior Scottish government civil servants was "unfair and unjust".
He said he had been given no opportunity to "see and therefore to properly challenge the case against me" and that he had "not been allowed to see the evidence".
Salmond has also claimed that someone within the Scottish government has "flagrantly and repeatedly" breached the confidential complaints process by leaking details to the Daily Record.
He is now seeking a judicial review of the new complaints procedure and has launched a crowdfunding appeal to fund his legal action.
© 2017 - All Rights with The Financial Express