Updated

MPs were on Friday set to hold a first vote on legislation that would guarantee an in-out referendum on the country's membership of the European Union by 2017.

Hundreds of MPs from Prime Minister David Cameron's eurosceptic Conservative party packed the House of Commons for the first parliamentary debate on the bill.

It has only a slim chance of success because of opposition from the Liberal Democrats, the junior partners in Cameron's coalition government, and the opposition Labour party.

But the Conservatives are using the bill to portray themselves as the only mainstream political party offering British voters a say on whether to stay or leave the EU.

The legislation enshrines in law Cameron's promise to renegotiate the terms of Britain's membership and then hold a referendum after the 2015 election.

He made the pledge under pressure from his party's rebellious right flank, and with an eye on the electoral threat posed by the anti-EU UK Independence Party (UKIP).

Lib Dem opposition prevents him from proposing a government bill, so Cameron has instead taken the unusual route of backing an individual Tory MP to push the referendum plan through parliament.

He has ordered all his party's lawmakers to support the plan, and said on Friday: "I'll do everything I can to support this bill and get it through the House of Commons."

He added: "I believe it can pass."

The bill has been presented by James Wharton, the youngest Conservative MP in parliament, after he came out top in a ballot of private members' bills.

Opening the debate on Friday morning, he said he believed the bill spoke for "many millions" of British people, who have not had a vote on EU membership since 1975.

An ICM poll published last month found 35 percent of people support an immediate referendum. Some 43 percent said they would vote to leave the EU, and 40 percent would vote to stay.

"This is about giving the British public a real say, a real choice between a best possible deal we can get from the European Union and if the public choose to leave, if that is what they want to do," Wharton said, to cheers from Tory MPs.

The Lib Dems, the staunchly pro-European party led by Deputy Prime Minister Nick Clegg, have rejected the bill as a "parliamentary stunt".

They note that the coalition government has already passed legislation requiring a referendum in the event of any new EU treaties or major treaty changes.

Labour MP Douglas Alexander, the party's spokesman on foreign affairs, said: "Instead of trying to get his backbenchers back in line, the prime minister should be spending his time getting the country back on track."

The Tories were expected to win Friday's vote as many Labour and Lib Dem MPs stayed away, but the bill is likely to get bogged down as it proceeds through the next stages of the parliamentary process.

Europe has long been a toxic issue for the Conservatives, leading to the downfall of late prime minister Margaret Thatcher in 1990 and weakening her successor John Major.