Barack Obama has urged Britain to stay in the EU, saying the world needed the UK's influence within Europe.

The US president, who has arrived in Britain for talks with David Cameron and lunch with the Queen, said membership of the European Union magnified the UK's status on the global stage.

His intervention in the bitter EU referendum debate led to claims of hypocrisy from Brexit campaigners, who had urged him to "butt out" of the UK's decision on June 23.

Writing in The Telegraph, the president highlighted the special relationship between his country and the UK "forged as we spilled blood together on the battlefield".

"As citizens of the United Kingdom take stock of their relationship with the EU, you should be proud that the EU has helped spread British values and practices - democracy, the rule of law, open markets - across the continent and to its periphery," he said.

"The European Union doesn't moderate British influence - it magnifies it. A strong Europe is not a threat to Britain's global leadership; it enhances Britain's global leadership.

"The United States sees how your powerful voice in Europe ensures that Europe takes a strong stance in the world, and keeps the EU open, outward looking, and closely linked to its allies on the other side of the Atlantic. So the US and the world need your outsized influence to continue - including within Europe."

The president said the deaths of tens of thousands of Americans in the battles to liberate Europe showed the strength of the ties between the US, UK and the continent.

"I will say, with the candour of a friend, that the outcome of your decision is a matter of deep interest to the United States," he said.

"The tens of thousands of Americans who rest in Europe's cemeteries are a silent testament to just how intertwined our prosperity and security truly are. And the path you choose now will echo in the prospects of today's generation of Americans as well."

Mr Obama's much-anticipated intervention comes as a boost to the Remain camp, but has infuriated senior figures in the Brexit movement.

The president said he realised there had been " considerable speculation - and some controversy - about the timing of my visit" but joked: "I confess: I do want to wish Her Majesty a happy birthday in person."

He said he realised there was a "spirited campaign under way here" and " ultimately, the question of whether or not the UK remains a part of the EU is a matter for British voters to decide for yourselves".

But he added: "In this complicated, connected world, the challenges facing the EU - migration, economic inequality, the threats of terrorism and climate change - are the same challenges facing the United States and other nations.

In today's world, even as we all cherish our sovereignty, the nations who wield their influence most effectively are the nations that do it through the collective action that today's challenges demand.- Obama

"And in today's world, even as we all cherish our sovereignty, the nations who wield their influence most effectively are the nations that do it through the collective action that today's challenges demand."

He said the UK had benefited from EU membership in terms of jobs, trade and growth - and highlighted the potential for the Transatlantic Trade and Investment Partnership (Ttip) deal.

Brexit-backing London mayor Boris Johnson said Mr Obama "would not dream" of involving the US in an organisation like the EU and accused him of being "downright hypocritical".

"This project is a million miles away from the Common Market that we signed up for in 1973," Mr Johnson wrote in The Sun.

"It is deeply anti-democratic - and much as I admire the United States, and much as I respect the president, I believe he must admit that his country would not dream of embroiling itself in anything of the kind.

"The US guards its democracy with more hysterical jealousy than any other country on earth."

He added: "For the United States to tell us in the UK that we must surrender control of so much of our democracy - it is a breathtaking example of the principle of do as I say but not as I do.

"It is incoherent. It is inconsistent, and yes it is downright hypocritical. The Americans would never contemplate anything like the EU, for themselves or for their neighbours in their own hemisphere. Why should they think it right for us?"

Ukip leader Nigel Farage said: "President Obama should butt out. This is an unwelcome interference from the most anti-British American president there has ever been.

"Mercifully, he won't be in office for much longer."

The Prime Minister, who will hold talks with Mr Obama in Downing Street before a joint press conference, defended the president's right to speak out on the EU issue.

He told BBC Radio Bristol: " I do think it's good to listen to your allies and friends and America, who work with us so closely, who lost a lot of people in the First and Second World Wars fighting alongside the British, as we often do.

"I think he is perfectly entitled to say, 'as a friend of Britain, I'm not going to tell you what to do, I'm just going to tell you what I think'."

Sign up to our free newsletters

Get the best updates straight to your inbox:
Please select at least one mailing list.

You can unsubscribe at any time by clicking the link in the footer of our emails. We use Mailchimp as our marketing platform. By subscribing, you acknowledge that your information will be transferred to Mailchimp for processing.