David Cameron will on Wednesday set a deadline to hold an in-out referendum on Britain's membership of the European Union by the end of 2017 as he hardens his position on the issue that has bedevilled Tory leaders for a quarter of a century.

To the delight of Eurosceptics, the prime minister will throw down the gauntlet to his fellow EU leaders to agree to a revision of Britain's membership terms within two and a half years of the next general election or risk triggering a British exit.

In his long-awaited speech on Europe, which has been repeatedly delayed since the autumn, Cameron will pledge no rest until he wins because democratic consent for the EU in Britain is "wafer thin".

The prime minister will say: "The next Conservative manifesto in 2015 will ask for a mandate from the British people for a Conservative government to negotiate a new settlement with our European partners in the next parliament.

And when we have negotiated that new settlement, we will give the British people a referendum with a very simple in or out choice to stay in the EU on these new terms; or come out altogether. It will be an in-out referendum.

"Legislation will be drafted before the next election. And if a Conservative government is elected we will introduce the enabling legislation immediately and pass it by the end of that year. And we will complete this negotiation and hold this referendum within the first half of the next parliament.

"It is time for the British people to have their say. It is time to settle this European question in British politics."

On Tuesday night, Labour leader Ed Miliband said Cameron's speech would "define him as a weak prime minister, being driven by his party, not by the national economic interest".

Prominent pro-Europeans are planning to lambast Cameron for placing a question mark over Britain's EU membership. One senior figure said: "This is dynamite. This is such a risk – it is an all or nothing strategy."

The prime minister's pledge to hold an in-out referendum on a relatively short timetable is the "red meat" which has prompted prominent Eurosceptics, such as the former defence secretary Liam Fox, to express satisfaction with the speech.

No 10 insists the prime minister is not adopting hostile tactics towards the EU, although some pro-Europeans suggested that Cameron had crossed a line by appearing to use the threat of a referendum within a relatively short timetable to strengthen Britain's hand in the negotiations.

Cameron will make clear to his 26 fellow EU leaders that a failure to offer Britain a referendum on new membership terms would increase the chance of a British exit. "The question mark is already there and ignoring it won't make it go away," he will say. "In fact, quite the reverse. Those who refuse to contemplate consulting the British people, would in my view make more likely our eventual exit."

Nick Clegg, who has been briefed by the prime minister on the speech, will reject Cameron's pledge to hold a referendum by 2017 on the grounds that it is wrong to commit Britain to such a specific timetable when there is uncertainty over whether negotiations will take place. The deputy prime minister's opposition means that the draft legislation for the referendum will have to be drawn up by Conservative special advisers outside the formal government and parliamentary routes.

A new cross party pro-European think tank supported by Kenneth Clarke warned the prime minister of the dangers of threatening to leave the EU. Peter Wilding, director of the Centre for British Influence, said:

"We support the prime minister's call for a more 'flexible adaptable and open Europe' and we will need positive partnership to achieve that, not threatened exit."

The prime minister's plans, which will involve tabling new British membership terms in a future EU treaty negotiation designed to agree new eurozone governance structures, may have run into trouble even before he delivers his speech. Angela Merkel and François Hollande agreed at a summit in Berlin on Tuesday, held to celebrate the 50th anniversary of the Elysée treaty, to publish joint proposals for the running of the eurozone at an EU summit in June.

The move by the leaders of Germany and France, who were upset by Cameron's initial plan to deliver his speech on the same day as their celebration marking their historic post-war reconciliation, means negotiations could take place earlier than No 10 had expected. The prime minister will be unable to table his demands for the repatriation of powers before the next election because Clegg has dismissed this strategy as "a false promise wrapped in a union jack".

The Franco-German timetable also raises the prospect that the negotiations could take place outside a formal EU treaty revision. German sources have indicated in recent weeks that Merkel has abandoned plans for the moment to demand a revision of the Lisbon treaty in the face of strong opposition across the EU, particularly from Paris.

The PM, who has briefed Hollande and Merkel on his speech, is understood to have accepted that he may have to table his demands outside a formal treaty negotiation. This raises the prospect that he could follow in the footsteps of Harold Wilson who negotiated small changes to Britain's EU membership terms outside the treaties ahead of the 1975 referendum.

Cameron will make clear in his speech that he will be demanding major changes, possibly including the repatriation of social and employment laws which could see Britain winning a complete opt-out from the working time directive. Downing Street sources have suggested that work is now complete on plans by Theresa May, the home secretary, to restrict benefits to EU citizens who are entitled to settle in Britain.

The prime minister will show the scale of his ambitions when he says: "Simply asking the British people to carry on accepting a European settlement over which they have had little choice is a path to ensuring that when the question is finally put – and at some stage it will have to be – it is much more likely that the British people will reject the EU. That is why I am in favour of a referendum. I believe in confronting this issue – shaping it, leading the debate not simply hoping a difficult situation will go away."

Downing Street insists the prime minister's goal is to strengthen Britain's position in the EU by winning greater support through renegotiated membership terms. He will say: "I believe something very deeply. That Britain's national interest is best served in a flexible, adaptable and open European Union. And that such a European Union is best with Britain in it."

But he will indicate that he may countenance a campaign for a no vote, if he fails to win his demands, when he says the status quo is unacceptable.

The prime minister will highlight his opposition to the status quo as he makes clear that he is opposed to an immediate referendum. This is designed to show he is adopting a consistent position after he forced Tory MPs to vote against an EU referendum in October 2011.

Cameron will say: "Some argue that the solution is...to hold a straight in-out referendum now. I understand the impatience of wanting to make that choice immediately.

"But I don't believe that to make a decision at this moment is the right way forward, either for Britain or for Europe as a whole. A vote today between the status quo and leaving would be an entirely false choice."

The prime minister will make clear that he is determined to see through his strategy. "Over the coming weeks, months and years, I will not rest until this debate is won. For the future of my country. For the success of the European Union. And for the prosperity of our peoples for generations to come."