Alex Salmond has resigned from the SNP.

The former first minister announced the decision on Wednesday evening in a video posted on YouTube.

It comes after two complaints of alleged sexual harassment emerged against him.

The politician denies the accusations and is taking court action against the Scottish Government to contest the complaints process activated against him.

He has also announced a crowdfunding campaign in a bid to raise £50,000 to cover his legal costs.

The allegations about Mr Salmond's conduct towards two staff members in 2013, while he was in office, first emerged last week when the former MP released a statement prompted by an inquiry from the Daily Record.

The newspaper published what it claimed were details of one of the complaints over the weekend.

Police Scotland confirmed on Friday that the complaints have been passed to the force.

Mr Salmond said he planned to reapply for SNP membership when he "clears his name".

In the video, Mr Salmond says: "I've 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've done the party - and the broader cause of independence - some service.

"I I truly love the SNP, and the wider independence movement. They've been the defining commitment of my life.

"But today I've written to the national secretary of the party, resigning my membership.

"I read carefully Nicola Sturgeon's statement and watched her television interview. She made it clear that the SNP have never received a single complaint about my conduct in my many decades of membership.

"And the Scottish Government have confirmed they did not have any such complaint before this January - more than three years after I left office.

"So let me be clear again - I refute these two complaints of harassment, and I absolutely reject any suggestion of criminality.

"I believe that all such issues must be treated seriously, confidentially and through a fair process. In this case, confidentiality has been broken, greatly to my detriment, but also in a way that now puts at serious risk the anonymity of both complainants.

"It urgently needs to be established - who breached that duty of confidence? And why?"

First Minister Nicola Sturgeon said last week she had been aware of the allegations but was unable to refer to them publicly to protect the integrity of the investigation.

She said her relationship with her predecessor "makes this an extremely difficult situation for me to come to terms with".

Mr Salmond said his resignation had been tendered with this in mind.

He said: "It seems obvious that Nicola feels under pressure from other political parties to suspend me from SNP membership, given recent party precedents.

"For my part I have always thought it a very poor idea to suspend any party member on the basis of complaints and allegations. Innocent until proven guilty is central to our concept of justice.

"However, 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.

"In my letter to the national secretary I state that it is my absolute intention to reapply for SNP membership just as soon as I have had the opportunity to clear my name. I hope that is by the end of this year. In the meantime I would urge no one else to relinquish their SNP membership."

Mr Salmond said he had launched the fundraiser to cover the "huge" legal costs of a judicial review.

He added: "Many have asked how they can help directly. Therefore I have established a crowd funder to assist with costs.

"All sums received will contribute exclusively to progressing the judicial review and any money left over will be used to support good causes in Scotland and beyond."

Nicola Sturgeon responded on Twitter to Mr Salmond's resignation.

She said: "I feel a huge sadness about this situation. 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.

"These last few days have been incredibly difficult for the party and, I am sure, for those involved in the complaints that have been made to the Scottish Government. I appreciate that they will have been difficult for Alex too.

"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".

A spokesman for the Scottish Conservatives said: "This is an overdue move, but one that plunges Scotland's governing party into turmoil.

"The fact he now has the brass neck to publicly crowdfund in the same breath as seemingly doing the right thing is astonishing.

"Scotland now faces the incredible and unprecedented situation of its most famous former First Minister appealing to SNP supporters for cash to take legal action against the government he used to run."

Scottish Labour's business manager and women's spokesperson Rhoda Grant said: "That an independently wealthy man with his celebrity and political power is to raise legal fees through a crowdfunder for a case ultimately linked to sexual harassment is unbelievable.

"It suggests that he is sending a signal to those who have made allegations that he has the upper hand.

"Decent people will rightly be furious that he is to raise money to take the Scottish Government to court.

"Alex Salmond is abusing his power, and dragging Scotland into the gutter."