Stephen Flynn speaking in the House of Commons, with Alison Thewliss seated behind him.
Stephen Flynn has been elected the SNP’s new leader at Westminster.
He succeeds Ian Blackford, who dramatically quit the post last week after five years in charge.
Flynn, the SNP MP for Aberdeen South, defeated Alison Thewliss by 26 votes to 17 to claim the top job.
As the leader of the third largest party at Westminster, he will be able to grill Rishi Sunak every week at prime minister’s questions.
Flynn’s victory is a blow for SNP leader Nicola Sturgeon, who is a key ally of Blackford and Thewliss.
Blackford decided to resign after it was made clear to him that he faced a leadership challenge from Flynn.
He was part of a group of SNP MPs who were unhappy with Blackford’s leadership, as well as Sturgeon’s attitude towards the party’s Westminster group.
It was initially thought that Flynn would be elected Westminster group leader unopposed until Thewliss, the party’s Treasury spokesperson, threw her hat into the ring on Saturday night.
The closeness of the result highlights the split among SNP MPs between those who are loyal to Sturgeon and others who are critical of her leadership.
Of his victory, Flynn said: “It’s an honour to be elected to lead the SNP’s strong and talented team of MPs during such a crucial period for Scotland.
“Under my leadership, SNP MPs will 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.”
Flynn’s deputy will be Mhairi Black, the MP for Paisley and Renfrewshire South.
She said: “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.”