Minutes after the vote closed on Thursday, it appeared the UK would stay in the EU. Even Ukip's Nigel Farage said it "looks like Remain will edge it".
However, when the final results came in, it was the Leave campaign that had won, prompting Cameron to announce that he would resign as prime minister before the Conservative Party conference in October.