Former Scottish first minister Alex Salmond has resigned his membership of the SNP amid allegations of sexual harassment.
Mr Salmond made the revelation in a video message posted on social media on Wednesday evening.
Two complaints were raised in January against the ex-SNP leader, who fiercely denies the allegations, and he was informed of an investigation in March.
Mr Salmond is taking court action against the Scottish Government to contest the complaints process activated against him, with papers lodged at the Court of Session in Edinburgh on Tuesday.
First Minister Nicola Sturgeon said she feels "a huge sadness about this whole situation".
In the message posted on Twitter, Mr Salmond said he has written to the party’s national secretary to resign his membership.
He stated: “I have been a member of the Scottish National Party for 45 years, 20 of them as party leader and seven as first minister of Scotland.
“I hope I have done the party and the broader cause of independence some service.
“Apart from a political spat back in the 1980s, that has been a period of continuous membership.
“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.”
Mr Salmond indicated that his resignation was to avoid potential divisions within the party.
He stated: “It seems obvious that (Scottish First Minister) Nicola (Sturgeon) feels under pressure from other political parties to suspend me from SNP membership, given recent party precedents…
“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.”
He added that it is his “absolute intention to reapply for SNP membership “just as soon as I have had the opportunity to clear my name”.
“In the meantime, I would urge no one else to relinquish their SNP membership,” he added.
Nicola Sturgeon said in a statement: "Alex has been my friend and mentor for almost 30 years and his contribution to the SNP and the independence movement speaks for itself.
"While the decision to resign has been Alex's alone, I understand why he has chosen to separate the current questions he is facing from the day to day business of the SNP and the ongoing campaign for independence."
In the statement posted on Twitter, the SNP leader continued: "I know party members will be upset by this news, just as I am. I also know there are many questions that can only be answered in the fullness of time. It is important now that any legal processes are allowed to take their course."