The UK’s ability to fight terrorism would be “more effective” if it sticks together with its European allies, the US President Barack Obama has said.
Writing in the Daily Telegraph Mr Obama also said being inside the EU magnifies Britain’s influence across the world.
The president arrived for a three-day visit of the UK late on Thursday.
But writing in The Sun, Vote Leave’s Boris Johnson said President Obama’s view was “a breathtaking example of the principle do-as-I-say-but-not-as-I-do”.
The president’s intervention in the UK’s forthcoming EU referendum on 23 June has been hotly debated and sparked claims of “hypocrisy” from those who want to leave the EU.
However, in his newspaper piece President Obama recognised that ultimately the matter was for British voters to decide for themselves.
But he also said: “…the outcome of your decision is a matter of deep interest to the United States.
“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.”
President Obama said that America’s relationship with the UK “forged as we spilt blood together on the battlefield”.
He also 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.”
He said the UK had benefitted from being inside the EU in terms of jobs, trade and financial growth.
“This kind of cooperation – from intelligence sharing and counter-terrorism to forging agreements to create jobs and economic growth – will be far more effective if it extends across Europe. Now is a time for friends and allies to stick together,” he wrote.
But Mr Johnson described Mr Obama’s argument as “inconsistent” and “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?”
And Mr Johnson described the notion that the UK has more influence inside the EU than outside as “nonsense”.
“The UK has been outvoted 40 times in Brussels in the last five years, and the total bill for those defeats – in extra costs for UK government and business – is put at £2.4bn a year,” Mr Johnson wrote.
Tory MP Iain Duncan Smith, who is also part of the Vote Leave campaign, also accused Mr Obama of double standards.
“I can imagine no circumstances under which he would lobby for the US Supreme Court to be bound by the judgements of a foreign court,” he said.
“Nor can I imagine any circumstances in which he would accept that laws should be made for- or taxes imposed on – the people of the United States without the approval of Congress.”
Obama’s UK stay is part of a tour which also includes a visit to Germany and Saudi Arabia – from where he has just left after having discussions with King Salman on issues including Iran, Syria, Yemen and the fight against so-called Islamic State militants.
He and First Lady Michelle Obama are due to have lunch with the Queen at Windsor on Friday, and dinner with the Duke and Duchess of Cambridge.
Mr Obama will also speak at a news conference with Prime Minister David Cameron.
Mr Obama arrived at Stansted Airport late on Thursday and was greeted by the Lord Lieutenant of Essex, John Petre, and the US Ambassador to the UK, Matthew Barzun.
The Obamas previously met the Queen, Prince Philip and the Duke and Duchess of Cambridge during their state visit in 2011.