David Cameron accompanied by his wife Samantha enters Number 10 after announcing his resignation
Photograph: Xinhua / Barcroft Images

At 10pm on Thursday, David Cameron’s team thought they were going to win. The prime minister had enjoyed dinner with his wife, Samantha, in Downing Street, and a circle of close advisers were present to watch the results come in.

Some flitted between No 10 and the remain camp party at the Royal Festival Hall on Thursday, but the core group included Craig Oliver, his communications chief; Liz Sugg, his head of operations; Graeme Wilson and Giles Kenningham, his press spokesmen; and his strategy director, Ameet Gill.

The downfall of David Cameron: a European tragedy

Read more

After winning, the plan was to draw a line under the bitter feuding of the EU referendum as soon as possible. Cameron was intending to announce a “life chances” strategy in the coming days in an attempt to cement a legacy as a moderniser, not as a leader known for dividing his party and the country over Europe.

As voting closed, the group was heartened by YouGov data predicting a 52-48 win for remain, and Nigel Farage’s concession that remain seemed to have edged it because his “friends in the City” were betting on the UK staying in. Remain sources in the Labour and Tory camps were texting journalists to say they were quite confident but it was still too close to call. “My gut says we will win,” said one female campaigner at Britain Stronger in Europe.

Little attention was paid to a bigger poll of 10,000 people commissioned by the Leave.EU founder and Ukip donor Arron Banks, which turned out to be on the money at 52-48 for leave.

Meanwhile, senior Vote Leave figures – from Matthew Elliott, its chief executive, to Gisela Stuart, the Labour chair of the campaign – had dined in Manchester at an Italian restaurant, San Giovanni, where they were pretty downbeat and resigned to a probable defeat.

Boris Johnson and his wife, Marina Wheeler, leave the polling station after voting in the EU referendum. Photograph: Carl Court/Getty Images

Boris Johnson had flown back late from his daughter’s graduation ceremony in Scotland, arriving just in time to vote and retreat to his townhouse in Islington, north London, where he holed up for the night.

Tears and cheers: Brexit reactions around the UK

Read more

One aide from the Vote Leave camp was spinning that they would be disappointed if it was more than a 10-point lead for remain, as well as laying into Farage for his unhelpful interventions.

It took a while for the tables to turn. “I can’t pretend we saw it coming,” said one person who was present in Downing Street.

The scale of the leave victory in Sunderland and narrowness of the remain win in Newcastle were the initial clues. It appeared that Farage’s friends in the City had called it wrong as the pound plummeted against the dollar and futures suggested a sharp fall for the FTSE when it opened.

The reality began to sink in further as it became clear that Wales was for leaving. The mood in No 10 grew extremely glum as a steady drip of areas were declaring two points below their own predictions.

Leave votes pile up at the count in Cardiff. Photograph: Tracey Paddison/REX/Shutterstock

At 3am, one Downing Street aide acknowledged it was “very tense”, while the female remain campaigner who had earlier felt an instinct that remain was winning reported that the Stronger In atmosphere was now despondent. “Labour voters have either said ‘fuck this’ and voted out, or stayed at home in the inner cities,” she texted.

In contrast, a Leave.EU party attended by Farage at Millbank was hotting up, with alcohol flowing and mini union jacks flying.

Around this time, the Ukip leader gave a premature but accurate victory speech, hailing the leave campaign for having secured independence “without having to fight, without a single bullet having been fired”.

'If you've got money, you vote in ... if you haven't got money, you vote out'

Read more

At 4.25am, journalists were told by Downing Street sources it was time to work on the assumption that leave was going to win, though they said the “show was not over till the fat lady sings”. Half an hour later the Stronger In bunch had pretty much thrown in the towel, saying: “From the campaign’s point of view, the British voter has spoken, and we respect their decision, but it is now over to the government. Our role here is done.”

There was now a naked fury towards Boris Johnson, Michael Gove and their strategists at Vote Leave, such as Dominic Cummings and Matthew Elliott. “All I can say is it feels like the lunatics have taken over the asylum,” one Tory remain camp insider said.

The Brexit team let it be known that their leading lights – Johnson, Gove and Stuart – would give no joint statement until after Cameron had made clear his position.

Johnson resolutely declined to emerge from his home to greet a gathering press, a bagpiper in full musical flow, and Kay Burley of Sky News knocking on his door at 4.50am.

During the intervening time, Farage was making hay on the airwaves, declaring it a victory for Ukip, common sense, ordinary people and decency. He began calling for Cameron to go, saying it was “curtains” for the prime minister, adding to voices from Labour, including Hilary Benn, the shadow foreign secretary, and Alan Johnson, the leader of the Labour in campaign.

From 6am onwards the buzz at College Green, which sits in the shadow of the Houses of Parliament, began to build. The broadcasters had converted the small patch of grass into a mini-Glastonbury, awash with tents and gazebos, in preparation for results day. First to arrive in the arena was Farage, who was greeted by a couple of dozen Brexiters cheering and singing Jerusalem.

As drivers tooted their horns in support, Farage declared “we got our country back” to more cheers. Soon afterwards, MPs from all parties and all sides of the debate made an appearance.

The Labour leaver John Mann claimed the referendum had been won by Labour voters; the former first minister of Scotland Alex Salmond declared a second independence referendum would happen in his home country; the Northern Ireland secretary, Theresa Villiers, tried to calm fears as Sinn Féin called for a border poll; the Labour peer and arch-Blairite Peter Mandelson lamented Jeremy Corbyn’s leadership. From tent to tent they moved, for radio, for TV, approached by journalists from across the world, from Italy to Japan.

Corbyn made an appearance shortly after 7am, calling for the government to trigger article 50 of the Lisbon treaty immediately and sounding relatively sanguine about the prospect of leaving, while stressing action was needed to stabilise the economic situation. A briefing note from his team to Labour MPs argued he was closer to the Eurosceptic centre of gravity of the voters than any other party leader, triggering fresh fury within the parliamentary party and calls for him to resign. The idea of a no-confidence vote in the Labour leader quickly began to circulate.

Cameron, who had grabbed a couple of hours of sleep by breakfast time, is understood to have taken the bad news for remain in a pragmatic way. He was ready for the prospect of resigning and one source said he did not speak to Gove or to Johnson before taking the decision to step down.

It was not until after 8am that the prime minister emerged from No 10 holding his wife’s hand. At the podium from which he had warned three days ago of the severe consequences of Brexit, he announced a decision to step down after the Tory party conference to allow fresh leadership to take the UK along the path it had chosen.

A pyrrhic victory? Boris Johnson wakes up to the costs of Brexit

Read more

He was quickly followed by a businesslike Mark Carney, the governor of the Bank of England, who said he would not “not hesitate” to steady the markets and make an extra £250bn available to the banks.

Two hours later, Johnson, Gove and Stuart emerged at the Vote Leave headquarters on Albert Embankment. As Johnson had left his house, a big north London crowd booed and shouted “shame on you”, as well as even ruder insults, in a reminder that most residents of the city he ran for eight years had voted to remain in the EU. In a sombre tone, the trio promised to keep Britain liberal and open to the world while reassuring people that “nothing will change in the short term”. They hurried off stage afterwards without taking questions from the world’s media.

With just a few weeks left until the summer recess, there was no time to waste among Cameron’s potential successors to start hinting about their candidacies. Johnson is taking time over the weekend to consider his options, while Nicky Morgan, Amber Rudd and Theresa May are also mulling bids from the remain side.

With his statement done, Cameron took some time out with his family, but he is still scheduled to make a public appearance on Saturday for Armed Forces Day in Cleethorpes, north-east Lincolnshire.

There will be no easy ride next week as he faces EU leaders at a summit in Brussels where the other 27 heads of government will discuss their common position on negotiating to divorce the UK from the rest of the bloc.

His renegotiation completed four months ago is void. EU leaders estimate that new trade deals and a financial settlement could take seven years. But Cameron has merely three months left of responsibility for dealing with the fallout that Brexit has caused.