In retrospect, all the signs were there. But six months ago, back in July 2009, no one actually guessed that Peter Mandelson was about to become Labour's seventh prime minister. The suggestion had been doing the rounds at Westminster, of course, as one of those frivolous "what if games" – such as "what if John Smith had lived", or "what if Tony Blair had sacked Gordon Brown in 2001". That wasn't the same as predicting the events of the hot summer to come.

Long before the bond crisis of late August, and Alistair Darling's resignation, which followed hours later, Lord Mandelson (as he was still known then) had been teasing journalists with his ambitions. In an interview with the Financial Times, published in June on the day Brown attempted one last relaunch, he was in flirtatious mood. "I can well do without it," Mandelson said, asked if he wanted to lead Labour. "I'm trapped," he added of his peerage. "I believe it is for life ... of course, you could always change the law."

At private dinners he was rumoured to go further, speculating on whether it was constitutionally possible to rule Britain from the Lords and citing Lord Salisbury as a precedent. But everyone took it as a bit of a tease: Peter being Peter, Labour's naughty uncle.

Looking back it is hard to understand why untested Alan Johnson was still seen as the obvious successor, or why indecisive David Miliband fancied his chances after twice ducking out of the challenge.

Mandelson had established himself as the second most senior member of the government and had insisted on the title to go with it – first minister. After years in Brussels, he had experience and credibility unmatched by anyone in British politics apart from Brown. There was talk of him becoming the first president of the European Union, if the Lisbon treaty was ratified. David Cameron's short stint as a television executive still looks small by comparison.

"Whenever I returned to London from Brussels or elsewhere in the world, I felt that Westminster was a bit parochial," Mandelson had told the FT in June. "But actually, it's nice to be home, and it's nice to be welcomed home."

Opinion differed on the warmth of the welcome and on what motivated Mandelson to keep the Brown premiership afloat. Some wondered whether he had, as he claimed, really changed his opinion about Blair's successor, or whether his deeper loyalty was to the Labour cause – or simply his own career. Everyone knew that he could have brought down Brown in the crisis that followed the European elections, but he had persuaded Blairites such as Miliband to stay loyal. Ironically, the beneficiary of that was to be Mandelson himself.

Brown never recovered from his June election drubbing, and the attacks on spending that Cameron pressed home over the summer. The prime minister came to depend more and more on Ed Balls and Shaun Woodward, the former Tory MP who had become a close ally – to Mandelson's barely disguised contempt. It was inevitable their refusal to admit that public spending had to be cut would fatally spook the markets.

In the last week of August, news hit the City that Standard & Poor's had downgraded Britain's credit rating. Hours later the Treasury announced an auction of £4bn worth of 25-year bonds at 4.5% had failed – dealers dismissed them as a risky punt compared with the security of German or US loans. The chancellor was forced by Downing Street to make a live broadcast dismissing the story as "incomplete and misleading". But when the governor of the Bank of England confirmed his deep alarm about Britain's inability to pay its way, Darling's resignation became inevitable.

Perhaps Brown might still have survived, if he had not gone to ground in his Fife family home. The street outside was blocked by satellite broadcast vans as reporters relayed news of his silence. The BBC even hired a helicopter (later much criticised as a waste of £12,000) to film the prime minister's empty back garden.

That afternoon a big British building society collapsed under the strain of bad loans in the commercial property market and the FTSE fell sharply. The prime minister's claim to have turned round the economy was in ruins.

He made one last effort to stay on, announcing from Scotland that Balls was to become chancellor and Woodward chief secretary, in charge of spending. The appointments simply added insult to injury. In London, the cabinet gathered to issue a private ultimatum: Brown must go or they would quit – and to everyone's surprise, he folded. He gave a dignified final statement to Sky News, before flying to Harvard with his family. He has not spoken in public since.

Given the circumstances, Labour's long-formal process of electing a leader was untenable – the new prime minister might not be in place much before Christmas. Under the party's constitution, the cabinet found itself able to postpone the contest and pick one of its own to serve immediately. Harriet Harman's Newsnight announcement that she expected to get the job only added to the panic. The next morning, Mandelson, as the dominant figure in the cabinet, was elected on a show of hands. He headed for Buckingham Palace and soon after swept into Downing Street in the prime minister's Daimler.

Polls showed that most people were unaware that it was constitutionally possible for a peer to be prime minister. Even constitutionalists were divided over whether the practice had fallen beyond revival into disuse – but the Commons was in such low esteem after the expenses scandal that voters did not seem to care. And conveniently, Speaker Bercow kept his silence.

After all, Mandelson's predecessor, Brown, had not been elected to the post either. And as someone pointed out, Clement Attlee had once declared Lord Salisbury, the last peer to enter Downing Street before Mandelson, to be the best prime minister of his lifetime. Journalists turned to Vernon Bogdanor's new book on the constitution, and found an appropriate quote from Trollope: "Anything is constitutional or anything is unconstitutional just as you choose to look at it."

Within days Mandelson had introduced a bill for rapid democratic reform of the Lords. He won support when he persuaded Vince Cable to become his independent chancellor. John Cruddas and James Purnell joined the cabinet; soon after, Mandelson – released from the Lords – fought and narrowly won a byelection to get him back into the Commons.

The general election date was confirmed well in advance: 6 May 2010.

With just months to go, an emergency programme of cuts has given the government an austere sense of purpose – the halving of the Olympic budget, the scrapping of Trident, and withdrawal from Afghanistan are said to be just the start. The Tories have been outflanked. At 34%, their poll rating is now just 1% ahead of Labour. The once unimaginable – a Labour fourth term – is on the cards. "A fighter, not a quitter", as somebody once said – but who would have thought that the path to power would be paved with ermine.