Richard Leonard, the Scottish Labour leader, has resigned just four months before elections for the parliament in Edinburgh, in which polls suggest his party is set for another heavy defeat by the Scottish Nationalists.

Mr Leonard, who has struggled to make much impact on Scottish voters and had fought off an attempted ousting by Scottish Labour colleagues in September, said in a surprise statement on Thursday afternoon that he was stepping down as leader with immediate effect.

As the only major leftwing party in Scotland that opposes independence, Labour’s fortunes have potentially far-reaching implications for the UK’s constitutional future. The SNP is seeking a renewed mandate for a second independence referendum at Scottish parliamentary elections scheduled for May, making Labour an important bulwark of continued UK union.

However, a poll of Scottish voters by Savanta ComRes for The Scotsman newspaper on Thursday found that only 18 per cent intended to vote for a Labour candidate in May, compared with 53 per cent who expected to back the SNP.

The relatively leftwing Mr Leonard, a supporter of former UK Labour leader Jeremy Corbyn, had previously insisted that he could turn round the party’s fortunes. But on Thursday he said he had thought “long and hard” about the political situation.

“I have also considered what the speculation about my leadership does to our ability to get Labour’s message across. This has become a distraction,” he said in a statement. “I have come to the conclusion it is in the best interests of the party that I step aside.”

One senior Labour figure said Mr Leonard had been pushed by his “union friends” to quit because of the party’s poor showing and his bad personal ratings. “His friends in the unions spoke to him,” the Labour figure said. “He was offered either the guillotine or the door, it was a deliberate decapitation strategy.”

Mr Leonard is a former organiser for the GMB trade union, a major Labour donor that represents workers in the manufacturing industry and public services. Senior figures from the GMB are understood to have acted as the “honest brokers” who persuaded Mr Leonard of the need for a “peaceful transfer of power”.

One member of the shadow cabinet said the defenestration was “inevitable” but said: “The last thing anyone wanted was Keir Starmer saying ‘you’ve got to go’ because Scottish Labour has to have a level of autonomy.”

Mr Leonard’s departure opens the door for a leadership contest that could highlight tensions between the Scottish party’s left and right wings.

In a reflection of the bitterness of Scottish Labour's internal divide, Neil Findlay, an MSP and ally of Mr Leonard, said he had been toppled by a “three-year campaign” of private briefings and leaks from “flinching cowards and sneering traitors”.

Anas Sarwar, a member of the parliament at Holyrood in Edinburgh who is generally considered a political centrist, is widely seen within Labour as a favourite to lead the party in Scotland. Mr Sarwar ran against Mr Leonard for the leadership in 2017.

The son of Mohammad Sarwar, the UK’s first Muslim MP, Mr Sarwar is a former deputy Scottish leader. One ally said he would be a strong contender. “He looks like and sounds like modern Scotland and has built up a reputation as a serious parliamentarian with an interest in international humanitarian issues,” they said.

Labour was the most powerful force in Scottish politics until the SNP won power at Holyrood in 2007. It fell to third place in the chamber after the Scottish Conservatives in 2016. Scottish Labour has since struggled to overcome divisions between its left and right wings and over its strategy of opposing a second independence referendum.