Five minutes after the polls closed on Thursday evening, the Scottish Labour hierarchy moved to save wounded leader Kezia Dugdale.

Sensing an electoral disaster even worse than the general election rout of 2015, the party sent out a "close of poll script" for senior figures to use if asked about Labour divisions.

The spoon-fed bullet points were clear: “We’re remarkably united around Kez’s leadership in Scotland.

“Kez led in Scotland from the front, she won the leadership with an overwhelming mandate. We’re united in Scotland and we have a long term plan to return the party to our roots.”

The lines provided useful cover throughout the night as the party faced up to an unprecedented humiliation.

Not only had Labour lost 35% of its MSPs, but a party that had once dominated Scottish politics for decades had been thumped by the hated Tories and relegated to third place.

In 1999, Donald Dewar won 1.7 million votes. Seventeen years later, Dugdale was barely able to poll half this amount.

Labour went into the election with one goal – come out ahead of the Tories by whatever means necessary – but the party failed spectacularly.

Dugdale, in post for nine months after succeeding Jim Murphy, tried to frame the Holyrood election as a battle between Left and Right, but got caught up in the post-referendum tornado of constitutional politics.

Activists and candidates, speaking on condition of anonymity, gave this newspaper a detailed account of the problems in the campaign and the long-term challenges facing Dugdale.

Senior figures were pleased that - for once - party strategists recognised the importance of the regional Lists in this election, but were perplexed by the ‘Both Votes Labour’ slogan.

Labour won three constituency seats, but a common view was that the List message was not as crisp as the Tory regional strategy.

“We knew we would get hammered on first-past-the-post, but our message gave the impression we were contenders. We should have focused on the second vote,” one insider said.

If the party’s electoral messaging was deemed to be confusing, candidates were scathing about aspects of the party's flagship tax policy.

The policy was simple in theory: a 50p income rate for millionaires; a 1p tax rise for basic rate payers; and a rebate for the poor.

In practice, the cash-back scheme - an "annual boost" - was so poorly explained that it had to be ditched. Evan Williams, the policy guru who wrote the manifesto, was blamed internally for the mess.

Party figures who want Dugdale to succeed also believe the left-wing tax policy lacked authenticity.

“She is a New Labour politician who backed an Old Labour agenda,” said one.

“She ran on a Corbynista platform even though she has contempt for that sort of politics”, said another insider.

A bigger problem, according to several candidates, was delaying the manifesto until the very tail end of the campaign.

The decision was partly tactical – Labour did not want the SNP stealing its clothes – but it was also down to Dugdale’s belief that initial drafts were simply not good enough.

As a result, Labour’s campaign became dominated by a tax rise, rather than on the specific ways extra investment would benefit families across the country.

“We focused on the pain, not the gain,” rued one candidate.

A credible alternative, one senior activist told this newspaper, would have been to unveil transformative policies at the beginning and then explain the necessity of a tax rise.

Instead, the big manifesto idea of free breakfast clubs was rolled out late and disappeared from the news cycle within 24 hours.

“All those tax powers are coming to Holyrood and we offered a free bowl of Frosties to kids,” one candidate moaned.

Another source flagged up the party’s ageing, dwindling core vote: “If we could have raised the voting age to 65 we would have been fine.”

BACKGROUND: Paul Hutcheon's articles charting a decade of Labour campaign failures

2007: The single seat heartbreak

2011: The landslide

2015: Inside the campaign from hell

Dugdale’s mixed messages on independence also frustrated colleagues.

In an election where polls showed nearly 90% of Yes voters backing the SNP, Labour was locked in a battle for No supporters with the Tories.

Ruth Davidson’s message was clear – outright opposition to a second referendum – but Dugdale told an interviewer it was “not inconceivable” she could back separation if it would secure Scotland’s membership of the European Union.

“The independence wobble was bigger than the tax issue,” said one insider. “It was a gift for the Tories.”

The early campaign row over the SNP’s Named Person scheme – whereby every child will have a single point of contact – also caused problems.

In Johann Lamont’s shadow cabinet, Dugdale had been a staunch supporter of the policy and was said to have clashed with her ally Jenny Marra on the hot-button issue.

However, when Tory concerns over the scheme began to dominate the headlines in the first week of the campaign, Dugdale changed tack and called for a review.

A Labour activist who backs Dugdale said the leader’s initial support for the Named Person scheme pointed to a wider worry, namely that she listened to “middle class folk in interest groups”, rather than ordinary Joes.

The forum for airing internal gripes was the campaign conference call for candidates every Monday, overseen by deputy leader Alex Rowley and general secretary Brian Roy.

On one of the calls, it was said that some unnamed individuals, some of whom had been MSPs, did not have high “contact rates” with voters: in other words, they were not working hard enough.

“You can imagine how that went down,” said one insider.

A lack of cash was also a huge problem. Large donations were almost non-existent and the UK party was not in blank cheque mode. Even the famous ‘battle bus’ of old was kept in the garage.

While billboards of Nicola Sturgeon were plastered across Scotland in the run up to the poll, Labour had to make do with what one candidate described as a “hi-vis, low budget” strategy of free social media and door knocking.

On the plus side, this was the first Holyrood election campaign Labour fought with no interference from the UK Party or MPs. However, Jeremy Corbyn still managed to irk his Scottish colleagues at the Glasgow HQ.

At a private campaign event in Coatbridge, staged to promote Elaine Smith’s left-wing candidacy, Corbyn made a speech about the election without mentioning Dugdale once.

But even without the usual melodrama between UK and Scottish Labour, the campaign still suffered from personality clashes.

A persistent gripe was that Dugdale and MP Ian Murray presided over an Edinburgh-based “clique” and that a small number of her favourites hogged prized television slots and press releases.

Williams and strategy chief Blair McDougall were Dugdale’s two top aides, but a source told this newspaper the pair are not close.

Dugdale appointed Rowley as the party’s campaign manager, but he was said to have misgivings about elements of the overall strategy.

And her relationship with former Prime Minister Gordon Brown, who had been unveiled as a last-minute secret weapon in previous campaigns, was also described as “non-existent”.

As the results poured in after midnight, the mood of senior Labour figures turned from grey to black.

One candidate told this newspaper he was 75% certain Labour would beat the Tories. He later downgraded his optimism: “20%.”

The private post-election “script” sent to candidates also revealed a clear attempt by the party hierarchy to drag Corbyn into any post-election blame game.

One section of the document referred to “Labour infighting/ Jeremy’s Leadership?” and suggested the recent row over anti-semitism had been an issue: “Obviously people still look at Labour across the UK, we wouldn’t have chosen to have the row about anti-semitism in the week before the polls.”

A senior party source said dismissively: “Corbyn is useless, but to blame the anti-semitism stuff for our result is just laughable.”

Dugdale will inevitably face questions about her future as leader, but even her detractors believe she must be given another five years to develop in the role.

Insiders believe she came across as an impressive figure during the campaign, unlike her predecessor, Jim Murphy, who was said to be unduly concerned by how big his picture was in the tabloids.

However, even Dugdale’s supporters have nagging doubts about whether she is ruthless enough to be a successful leader.

After succeeding Murphy, she promised new faces in her parliamentary group and even considered imposing candidates on party members.

She failed to get her way and sitting MSPs were allowed to stand in the selection contests. Some of her colleagues deemed to be of questionable ability were re-elected on Friday.

One source said: “She needed to be a bastard and say ‘here’s your gold watch, now f**k off’.”

Others believe Dugdale needs “better staff” working for her. Williams was perceived to have produced an underwhelming manifesto, while McDougall is seen as someone in need of a fresh challenge.

However, the impending cut to Labour’s Short Money – cash that funds the Opposition - leaves Dugdale with little room to bring in new talent.

With 37 MSPs, Labour would receive £295,889 a year to hire staff. With 24 representatives, the budget falls to £191,448.

The wider point is whether Scottish Labour is past the point of no return.

The 2011 Holyrood election result was considered to be a nadir for the party, but last year’s result at Westminster was worse. Friday morning ranked even lower than that catastrophe.

“We are in a spiral of decline,” said one insider. “And I can’t see how we can stop it.”