The SNP chief executive Peter Murrell has resigned with immediate effect in a row over party membership.
Mr Murrell, who is married to outgoing party leader Nicola Sturgeon, said he had become a distraction to the leadership race.
The party has been forced to confirm a large drop in its membership numbers, which it had previously denied.
Mr Murrell had been set to face a vote of no confidence had he not stepped down, the BBC understands.
Two leadership candidates, Kate Forbes and Ash Regan, have questioned the independence of the election process.
And on Friday, the SNP’s head of media at Holyrood, Murray Foote, resigned, saying there were “serious issues” with statements he had issued in “good faith” on behalf of party headquarters.
A National Executive Committee source told the BBC Mr Foote had been “thrown under the bus” by Peter Murrell who accepted responsibility for a misleading statement about SNP membership numbers
Mr Murrell has been chief executive of the SNP since 2000 and married to Ms Sturgeon since 2010.
In his resignation statement he said: “Responsibility for the SNP’s responses to media queries about our membership number lies with me as chief executive.
“While there was no intent to mislead, I accept that this has been the outcome.
“I have therefore decided to confirm my intention to step down as chief executive with immediate effect.”
He said he had not planned to step down until after the leadership contest but recognised that he had become “a distraction from the campaign”.
“I have concluded that I should stand down now, so the party can focus fully on issues about Scotland’s future,” he said.
Mr Murrell added that he had no role in the running of the election contest.
“I have worked for independence all my life and will continue to do so, albeit in a different capacity, until it is achieved – and I do firmly believe that independence is now closer than ever,” he said.
SNP leadership candidate Kate Forbes said: “I think that the party owes Peter Murrell a great debt of gratitude because he oversaw the party’s expansion in membership and he’s been the reason we won so many elections with his leadership at the top.
“I’ve said repeatedly from the beginning of this contest that I think there’s an appetite for fresh faces and that will hopefully pave the way for new people in headquarters to be able to run the SNP in a way that maintains the trust of SNP members and supports the SNP in government.”
Ms Forbes added that despite having called for an independent auditor to oversee the leadership vote, she had “no concerns” about Peter Murrell.
This is a miserable end to Peter Murrell’s long career in charge of SNP headquarters where he helped turn the party into a successful election winning machine.
He is taking responsibility for the party misleading the media about a big fall in the SNP’s membership but concerns about his stewardship go wider than that.
Two leadership candidates called for an independent auditor to be appointed to oversee the election although Mr Murrell insists he had “no role in it at any point”.
There is an ongoing police investigation into how £600,000 raised by the party for independence campaigning has been spent – with the SNP denying any wrongdoing.
Some members of the party’s ruling body were threatening a vote of no confidence in the chief executive, with one telling the BBC he had become a “hindrance”.
Others in the SNP have long questioned the wisdom of the party being run by Nicola Sturgeon’s husband – arguing that too much power has been concentrated in one household.
Humza Yousaf, another SNP leadership hopeful said: “Peter Murrell has been an outstanding servant of the independence movement and the SNP.
“As I have said repeatedly throughout this campaign, he is the most electorally successful chief executive of any party in the UK and the SNP has been lucky to have him. Our election wins from 2007 to 2021 owe much to his political abilities.
Mr Yousaf added that he agreed it was time for Mr Murrell to stand down.
“With less than 10 days to go in this leadership contest, it is vital we all focus on the policies and vision we have for the party, movement and country,” he said.
Party leadership candidate Ash Regan posted on Twitter: “Eight years ago was the point where it was unacceptable to have the husband of the party leader as the CEO.
“I am encouraged to see the democratic foundations of the party now asserting their rightful function.”
She added that the SNP’s foundations were based on accountability, transparency, modernity and accessibility.
‘Questions to answer’
Questions have mounted over a loan of more than £100,000 that Mr Murrell gave to the party in June 2021 to help it out with a “cash flow” issue after the last election.
Scottish Conservative chairman Craig Hoy MSP said: “A fish rots from the head down – and the same applies to the SNP.
“Peter Murrell’s resignation is long overdue – but there remain serious questions for him to answer, not least over the ‘missing’ £600,000 from party accounts.”
He added: “The brutal, shambolic SNP leadership election appears to have been the tipping point that’s forced the first minister’s husband to quit before he was pushed.”
Mr Hoy said Mr Murrell must fully co-operate with any probes into the way the leadership election had been run and the police inquiry into the SNP’s finances.
In recent months, Ms Sturgeon was repeatedly asked about the origin of finances used by her husband but said the funds were entirely his own and she could not recall when she first learned of it.
The SNP has also been under investigation over the past 18 months after questions were raised about the fate of £600,000 that was raised from supporters in 2017 for the purposes of a future referendum campaign.
An SNP spokesman said the loan was a “personal contribution made by the chief executive to assist with cash flow after the Holyrood election”.