Media playback is unsupported on your device Media caption "Having the UK in the European Union gives us much greater confidence about the strength of the transatlantic union" - US President Barack Obama

The UK must stay in the European Union to continue to have influence on the world stage, US President Barack Obama has told the BBC.

He said the UK's EU membership "gives us much greater confidence about the strength of the transatlantic union".

But British Eurosceptic politicians criticised his intervention, saying it was up to Britain to decide.

David Cameron has said a referendum on whether or not to remain a member of the EU will be held by the end of 2017.

That referendum will follow a renegotiation of the existing terms of British membership.

The prime minister has said he will campaign for Britain to remain in the EU if he gets the reforms he wants.

Speaking to the BBC's North America editor Jon Sopel, he said the EU "made the world safer and more prosperous".

Mr Obama said the UK was America's "best partner" because of its willingness to project power beyond its "immediate self-interests to make this a more orderly, safer world".

'Standard consensus'

But former Environment Secretary Owen Paterson, now a leading eurosceptic backbencher, said President Obama was "trotting out the standard State Department consensus".

He told the BBC that the United States "two centuries ago fought not to have laws imposed on them so I don't think he's in a strong position when we want to make our own laws in our own Parliament".

"It is massively in America's interest that a strong UK, using all its contacts in the anglosphere, with Canada, New Zealand and Asia regalvanises the movement for world free trade that would be massively positive for thousands of people."

Image copyright Reuters Image caption The UK is set to have a referendum by the end of 2017 on whether or not to remain a member of the EU

Fellow Conservative backbencher Tom Pursglove said the issue of EU membership was "a matter for the British people".

"It isn't for anybody else to tell the British people what they are going to do," he said.

'Weakness and indecision'

And Conservative MEP Daniel Hannan tweeted: "I accept that there may be some arguments for staying in the EU. Humouring Barack Obama is not one of them."

Leading UKIP figures also criticised Mr Obama, the party's deputy leader Paul Nuttall describing him as the "most anti-British (US) president in a generation".

But Labour, which is now backing an EU referendum after having long opposed it, said Mr Obama should be listened to.

"Labour is fighting to protect Britain's interests by campaigning to remain in Europe while David Cameron's weakness and indecision are putting our country's future international influence and prosperity at risk," said shadow foreign secretary Hilary Benn.

And pro-EU campaign group Business for New Europe said Mr Obama's "carefully considered words show once again what is at stake in this referendum campaign".

"Our place in Europe doesn't just make sense in Washington - our status in capitals around the world is enhanced by our place at Europe's top table," said its campaign director Lucy Thomas.

'Very concerned'

Mr Obama described the UK's prime minister as an "outstanding partner" and congratulated his government for meeting the Nato target of spending 2% of the country's national income - GDP - on defence.

Earlier this year the head of the US Army, Chief of Staff Gen Raymond Odierno, said he was "very concerned" about the impact of spending cuts on the UK's armed forces.

At the time the Ministry of Defence said the government was committed to Nato's target. Earlier this month Chancellor George Osborne pledged to meet the target up to 2020 in his Budget.

In his BBC interview, Mr Obama denied putting pressure on Mr Cameron to meet that target but said there had been an "honest conversation" between the two leaders.

The US president, who has 18 months left in power, also admitted that the failure to pass "common sense gun safety laws" in the US was his biggest frustration.

He was speaking to the BBC at the White House before departing for Kenya, where he begins a short tour of Africa on Friday.