Cameron was trying to reduce the scope of EU integration with the UK (esp freedom of movement), with the threat he didn't want to use of a referendum, the EU said no (as the other commenter explained partly to disincentivize others, but also because they thought he was bluffing and people would never vote to leave), so the referendum was held.
It's literally what happened.
Cameron was trying to reduce the scope of EU integration with the UK (esp freedom of movement), with the threat he didn't want to use of a referendum, the EU said no (as the other commenter explained partly to disincentivize others, but also because they thought he was bluffing and people would never vote to leave), so the referendum was held.