“All political lives end in failure.” These were the words of David Cameron when he realised he had lost the EU referendum in the early hours of 24 June, according to his biographer Anthony Seldon.

The night before Mr Cameron made his resignation speech, the mood of the Prime Minister and his team swung from jubilant to morose as results came in and it became clear the Leave campaign had won.

And despite pleas from some of his closest allies, including George Osborne, to stay on as Prime Minister in the case of a Brexit win, Mr Cameron decided before the first results were announced that he would quit if he lost the referendum.

In an extract from an updated version of Mr Seldon’s biography of Mr Cameron published in The Times, the Prime Minister is quoted telling cabinet office minister Matthew Hancock “It’s not good, is it?” at about 3:30am, when his defeat became apparent.

“I’m going to have to go,” said Mr Cameron. “I don’t want to lead a Government where I don’t agree with its policy.”

Previously that evening, Oliver Letwin, the Prime Minister’s troubleshooter, had advised him to stay for the stability of the country, wrote Mr Seldon.

Mr Osborne, the Chancellor of the Exchequer, said Mr Cameron should only stay if he was prepared to fight, while communications director Craig Oliver said he should avoid appearing to “cling on” and leave, continuing his duties as Prime Minister during the leadership contest.

Brexit: David Cameron resigns

As the first results came in from Newcastle and Sunderland just after midnight and were worse for the Remain camp than expected, “a shudder passed through the group,” wrote Mr Seldon.

As other results were announced, showing a clear tendency towards Britain leaving the EU, Mr Cameron called a meeting in his study and made his intentions to resign clear.

“All political lives end in failure,” he told them.

The words are a quote from Enoch Powell, the Conservative politician best known for his infamous anti-immigration “rivers of blood” speech in the 60s.

In a 1977 biography of Joseph Chamberlain, Powell wrote: “All political lives, unless they are cut off in midstream at a happy juncture, end in failure, because that is the nature of politics and of all human affairs.”

David Cameron's premiership - in pictures Show all 15 1 /15 David Cameron's premiership - in pictures David Cameron's premiership - in pictures Britain's Queen Elizabeth II greeting David Cameron at Buckingham Palace for an audience to invite him to be the next Prime Minister on 11 May 2010 PA David Cameron's premiership - in pictures Prime Minister David Cameron and his wife Samantha wave from the steps of Number 10 Downing Street on 11 May 2010 Getty Images David Cameron's premiership - in pictures On 12 May 2010 Prime Minister David Cameron said in a press conference with Lib Dem leader Nick Clegg, who was then deputy PM, they plan to "take Britain in a historic new direction" and Conservative-led coalition government would be united and provide "strong and stable" leadership Rex David Cameron's premiership - in pictures A decade ago, David Cameron visited the Arctic to witness the effects of climate change. However since coming to power in 2010, his government has gradually dropped down a succession of green policies David Cameron's premiership - in pictures Prime Minister David cameron told the then New York mayor Michael Bloomberg, the Queen had “purred down the line” after he told her Scotland had voted against independence in September 2014. He was forced to apologise for breaking constitutional convention Getty Images David Cameron's premiership - in pictures Britain's Prime Minister David Cameron greeted soldiers working on flood relief in York city centre after the river Ouse burst its banks, in northern England in December 2015 REUTERS David Cameron's premiership - in pictures Claims that David Cameron performed an obscene act with a dead pig and smoked cannabis during his studies at Oxford University spread around the world in September 2015. The extraordinary allegations were made in an unauthorised biography of the Prime Minister written by Lord Ashcroft David Hartley/REX Shutterstock David Cameron's premiership - in pictures In 2016, Mr Cameron was caught up in a worldwide scandal dubbed the “Panama papers” Reuters David Cameron's premiership - in pictures Prime minister David Cameron and his wife Samantha with seven week old Regan as they meet her parents, first time home buyers Robert Arron and Kelly Jeffers at the Heritage Brook housing development in Chorley, Lancashire. David Cameron has joked that he wants "another baby" and said that he feels a "bit broody" every time he sees a newborn on the campaign trail David Cameron's premiership - in pictures Prime Minister David Cameron was criticised for branding refugees in the Calais ‘jungle’ camp as a “bunch of migrants” in January 2016 after thousands of refugees died in their attempt to cross the Mediterranean in 2015 Sky News David Cameron's premiership - in pictures Britain's Prime Minister David Cameron speaks with European Commission President Jean-Claude Juncker during an EU summit meeting on 17 March 2016 at the European Union council in Brussels. Cameron was in Brussels to renegotiate deal of UK membership with other European leaders. The deal, sealed after hours of haggling at a marathon summit, paved the way for a referendum on whether Britain will stay in the EU AFP/Getty Images David Cameron's premiership - in pictures President Barack Obama shakes hands with British Prime Minister David Cameron at a meeting at 10 Downing Street in London on 22 April 2016. The President and his wife visited 10 Downing Street where he joined press conference with British Prime Minister David Cameron and made his case for the UK to remain inside the European Union Getty Images David Cameron's premiership - in pictures After David returned from Brussels claiming victory in his renegotiation with European leaders, Boris Johnson announced that he will not support the Remain campaign. The prime minister said publicly he was "disappointed but Boris remains a friend" PA David Cameron's premiership - in pictures Prime Minister David Cameron makes a joint appearance with Mayor of London Sadiq Khan as they launch the Britain Stronger in Europe guarantee card at Roehampton University on 20 May 2016 in London. The 'guarantee card' lists five pledges should Britain remain in the EU, including the protection of workers' rights, full access to the single market and stability for Britain David Cameron's premiership - in pictures Britain's Prime Minister David Cameron speaks outside 10 Downing Street on 24 June 2016. Cameron announced his resignation after Britain voted to leave the European Union after a bitterly divisive referendum campaign AP

Since Mr Cameron's resignation, Theresa May, Michael Gove and pro-Brexit Andrea Leadsom have announced their intentions to stand for leader of the Conservative Party.

Work and Pensions Secretary Stephen Crabb and MP Liam Fox are also in the running.