Stephen Flynn is the SNP’s new Westminster leader, defeating rival Alison Thewliss to replace Ian Blackford. 

The result is a blow for Nicola Sturgeon, with the parliamentary party snubbing her close ally in favour of a candidate who looks set to distance the group from the leadership in Edinburgh. 

Despite claims from both sides that the vote would be close, Mr Flynn and his running mate Mhairi Black ended up winning comfortably, taking 26 votes to Ms Thewliss's 17.

The Tories described it as a "personal humiliation" for the First Minister. 

In a statement, Mr Flynn said his MPs would be "relentlessly focused on standing up for Scotland's interests and our democratic right to decide our future in an independence referendum."

"Families across Scotland are paying a devastating price under Westminster control, with Brexit, austerity cuts and the Tory cost of living crisis hammering household budgets.

"SNP MPs will work harder than ever to hold the Tory government to account - and make the case that independence is the essential route to safety, fairness and prosperity for Scotland.

"I would like to thank Alison Thewliss and Stuart McDonald who are both hugely talented MPs and will continue to play a key role in our movement.

"I would also like to pay tribute to Ian Blackford MP and Kirsten Oswald MP, who have been a fantastic leadership team and will be welcome sources of advice as we move forward together."

Ms Black said: "I'm delighted to have been elected as SNP Westminster Deputy Leader and look forward to working closely with Stephen Flynn and MP's across the parliamentary party as we stand up for Scotland and make the case for independence.

"Westminster is failing Scotland.

"With the Tories and Labour Party both wedded to Brexit, austerity cuts and democracy denial, it's clearer than ever that independence is the only way to escape the damage of Westminster control and get Scotland back on the path to prosperity."

The First Minister tweeted her congratulations to Mr Flynn and Ms Black describing them as a "truly formidable team."

"Congratulations to new @theSNP Westminster leader @StephenFlynnSNP and deputy leader @MhairiBlack - a truly formidable team. Looking forward to working with them both."

Mr Flynn - who was only elected just three years ago - takes over from Mr Blackford with immediate effect and will face Rishi Sunak at Prime Minister's Questions tomorrow at noon.

Ms Thewliss took to Twitter to congratulate her rival. 

"Congratulations to StephenFlynnSNP and @MhairiBlack, and my thanks to all who have been so lovely and supportive - especially my running mate 
@Stuart_McDonald."

In the immediate aftermath of Mr Blackford's resignation, most had expected a coronation for Mr Flynn. 

Ms Thewliss shocked the party when she announced her bid on Saturday night, just two days after Mr Flynn had held a meeting with the First Minister in Bute House. 

Some MPs viewed her candidacy as the First Minister's attempt to kibosh Mr Flynn's leadership ambitions. 

He was part of the so-called Tuesday Club, whose members, including David Linden, Gavin Newlands, Alan Brown, had been critical of Mr Blackford since a vote on benefits in February.

The SNP leadership in Edinburgh had urged MPs to abstain on a vote to raise benefits by just £10.07 a month and the state pension by £5.55 a week.

However, Mr Linden and Glasgow South West MP Chris Stephens defied the party’s orders and voted against the Government.

Mr Flynn has also publicly split with the First Minister over oil and gas exploration.

Last year, when Ms Sturgeon wrote to the then prime minister, Boris Johnson, calling for all new oil and gas extraction licenses to be reassessed in light of the climate crisis, the Aberdeen South MP warned about being “in a situation where we are ever more reliant on imports.”

However, one SNP MP told The Herald they were confident the group would come back together behind Mr Flynn. 

"Not a coronation, so everyone knows we need to unite, and Stephen knows it more than anyone," they said.

Scottish Conservative chairman Craig Hoy said: “Stephen Flynn’s victory over Nicola Sturgeon’s candidate is a personal humiliation for the First Minister and lays bare the deep splits within the SNP.

“Mr Flynn was the MP who brought down Ian Blackford, in open defiance of the First Minister who inexplicably stood by Mr Blackford despite his shameful mishandling of the Patrick Grady scandal.

“Now, having persuaded Alison Thewliss to stand as the ‘stop-Flynn’ candidate, Nicola Sturgeon has been overruled again by her rebellious Westminster MPs.

“It’s clear that the First Minister’s once-iron grip on her party is slipping. This result is sure to lead to increased tensions between the SNP leaders at Westminster and Holyrood, not least over oil and gas policy, where Mr Flynn – a serial flip-flopper on this issue – is, for the moment, at odds with Ms Sturgeon.”

Lib Dem MP Christine Jardine described the result as a "nasty rebuke" for the First Minister. 

She added: "Stephen Flynn takes over a divided Westminster group obsessed with completely the wrong priorities.

"With energy bills and inflation soaring and public services feeling the strain, he should tell his parliamentary group to get on with what really matters.

"Sadly, I won't be holding my breath."

Labour's Shadow Scottish Secretary Ian Murray described Mr Flynn's victory as a "two finger salute to Nicola Sturgeon."

“The fact is that this is nothing more than shuffling the deckchairs on the Titanic," he added. 

The vote at the parliamentary group’s AGM came after a valedictory speech by Mr Blackford. 

Earlier in the day, he too paid tribute to colleagues and staff,

He tweeted: “Today is my last day in office for @theSNP as Westminster leader. Thank you to colleagues for the opportunity to serve both MPs and staff as well as all those who have supported and encouraged me. Good luck to my successor as look I forward to my next challenges.”

Ms Sturgeon replied to say “thank you.”