AS Glasgow woke up on Friday morning, the Saltire was flying at full sail over the City Chambers.

For weary SNP activists crossing George Square on their way to the count at the Scottish Exhibition Centre, it must have seemed a good omen.

Indeed, the same image had adorned the brochure for the SNP's spring conference in March. Then, Alex Salmond, had got delegates cheering at the SECC by proclaiming "the SNP are coming" to Glasgow for the local elections. At the time, it had seemed less like a prediction and more a statement of the inevitable.

For more than two years, everything had seemed to come into alignment for an SNP win.

In spring 2010, Steven Purcell suddenly resigned as Glasgow City Council leader and it emerged he had been taking cocaine and warned by police about being open to blackmail by gangsters as a result.

In the aftermath, Labour chose Gordon Matheson as their new leader, leading to fierce infighting. A year later, the SNP triumphed in Glasgow at the Holyrood elections, winning previously rock-solid Labour seats and the popular vote in the city.

Going on to end 32 years of Labour control in Scotland's biggest council would assert the SNP's new dominance of the political landscape, and act as a springboard to independence.

Labour's response was to cull its "dead wood", deselecting almost half its councillors last autumn in order to introduce fresh talent. The result was even bloodier infighting. Six ex-Labour councillors even formed a new party, Glasgow First, to fight their old colleagues.

The SNP could hardly believe their luck and overhauled their own election plan. At the last poll in 2007, the party had been ultra-cautious, standing single candidates in 20 of the 21 wards, while Labour stood two or three. Only in Baillieston, where the former Glasgow East MP John Mason had a huge personal vote, did the party dare pop a second head over the parapet.

The result was that while all 22 of the SNP's people were elected, Labour romped home with an absolute majority of 45.

It was a miscalculation the Glasgow SNP, and their de facto boss, SNP deputy leader Nicola Sturgeon, were determined not to repeat. For 2012 they stood two candidates per ward, plus three in Sturgeon's political backyard of Govan, making 43 in total. If 40 got elected, the SNP would have a majority.

But while it looked good on paper, or amid the rhetoric of party conference, the reality was that the SNP always faced a tough uphill fight.

To replace Labour as the biggest party, they had to nearly double their seats, and pick up an extra councillor in almost every ward. It was never going to be easy.

Not that you would have known it from the faces at the SECC as the count doors opened at 9am. Seasoned Labour politicians were downcast, saying the "terrible turnout" had helped the SNP.

In contrast, the Nationalists appeared desperate to empty the ballot boxes. Many shared the view of Humza Yousaf, the Glasgow MSP, who had predicted a narrow SNP majority on Twitter the night before.

But as the first results were announced around 11am, it was clear the SNP had misfired badly.

In Newlands/Auldburn the result was no change. In Greater Pollok, the SNP made a gain, but only because Labour stood fewer candidates. In Linn, it was again no change, as even the Liberal Democrat fended off the Nationalists.

SNP activists began to look decidedly uneasy. They were failing to punch through and make those crucial gains, and they knew it. SNP number-crunchers predicted that if the trend continued, Labour would be on the brink of a majority, with the SNP eight or nine behind.

Just after 12.30pm, the candidates from Govan trooped into a make-shift room behind the stage to hear the sixth declaration of the day.

The result carried huge weight both in terms of arithmetic and symbolism. A big win in Govan would be a turning point. So anxious was Sturgeon to hear the result that she tried to listen through the curtains screening the candidates and got ticked off by officials.

She would have done better to stay clear. Instead of hitting their target of three, the SNP got just one, while Labour got two, and a deselected Labour councillor, Stephen Dornan, made it back under the Glasgow First banner.

If the SNP had stood two, they would have won two. But by over-reaching, they diluted their own vote and let Dornan slip in at the last.

Labour immediately grasped the significance. Failure to advance in Govan meant the SNP wouldn't have the numbers to control the council. "That's it!" exclaimed Labour councillor George Redmond. "We're going to be the administration."

Tom Harris, the Labour MP for Glasgow South, also recognised it was game over for the SNP. "We may not get a majority, but we'll be the biggest party, and I'll take that after the last year we've had," he said with relief.

The news for Labour just got better and better. As the results were announced in geographical order, starting in the south of the city where SNP support was highest, Labour had expected to be behind initially, but hoped to catch up when the north of the city declared.

Instead, by the halfway mark, when the wards along the Clyde were declared, they found themselves comfortably ahead with their best turf yet to come.

Gordon Banks, the Ochil MP behind much of Labour's campaign, predicted another majority in store. And so it proved. Just before 5pm, the East Centre result delivered three more Labour councillors, and the party passed the magic 40 mark, leading to extraordinary scenes beside the stage as Labour's jubilant Scottish deputy Anas Sarwar bearhugged Banks and the other campaign director, James Kelly MSP.

A few feet away, many in the SNP team were having to choke back tears. "We got carried away," admitted one. "We should not have thought we were going to win this."

Others acknowledged the SNP's "voter management strategy" simply hadn't been up to scratch. Under the STV system used for council elections, parties divvy up wards between their candidates and issue different leaflets in different areas. For instance, 'Vote Smith 1, Jones 2' in one patch, and 'Vote Smith 2, Jones 1' in another. If voters follow the instructions in each area, it maximises crucial transfer votes.

In 2007, it was a discipline the SNP didn't need to master because it mostly fielded single candidates and simply urged "Vote SNP No1". But in 2012, because it was fielding more people, it needed to change its game, and it failed.

Labour, on the other hand, had been through the exercise before in 2007 and had learned from it.

The statistics speak for themselves. The SNP stood 43 candidates and 27 were elected. Labour stood 45 and 44 were elected.

It shows Labour's voter management strategy was almost pitch perfect – the party fielded the right number of people, tailored its leaflets within each ward, and maximised its transfer votes.

The SNP also suffered from having an inept group leader in Allison Hunter, a Sturgeon crony who was exposed as hopelessly out of her depth. During the campaign she admitted she hadn't thought of any policies to implement if the SNP won, and might not stay on as leader past June.

Crucially, she also said a Glasgow win would be a "stepping stone to independence". She was a gift to Matheson who contrasted his track record and ideas for Glasgow with the SNP's lack of vision and an obsession with independence over bread-and-butter issues.

The SNP postmortem has already started. One senior SNP figure said the party hierarchy had failed to get the best candidates in place in Glasgow and elsewhere, then failed to provide them with policies to sell on the doorstep.

"The manifesto in Glasgow was tepid. What exactly were we saying beyond repeating that we would freeze the council tax? The other thing that hurt us was Alex Salmond and Rupert Murdoch, the feeling that Salmond is too close to big business and needs to show some humility."

Labour also reported the Murdoch factor cropping up in the closing days, as the Leveson Inquiry and rows over BSkyB dominated the airwaves. Labour said that since the New Year, and David Cameron's intervention in the constitutional debate, independence had been a big factor.

The more the SNP raise it, the less voters like it, said Labour councillor Malcolm Cunning.

The SNP spin after the Glasgow count was of solid progress – up five councillors. But the truth is a huge failure to live up to its own expectations.

The SNP gains were at the expense of four LibDems and one Scottish Socialist elected in 2007. But they basically didn't lay a glove on Labour.

Poor organisation, weak leadership, an uninspiring message and over-confidence were the culprits.

The SNP thought momentum from the Holyrood election would carry them over the line. Blinkered activists also thought they had right on their side, that they were irresistible.

Cynical Labour hands had no such illusions. They knew that after 2011 they had to grind out a win by pounding streets and eyeballing voters.

"You don't win elections on Facebook and Twitter," observed Labour councillor Jon Findlay.

What exactly were we saying beyond repeating that we would freeze the council tax

''