Barack Obama has urged the UK to stick with the EU, as he starts his final trip to Britain as US president by having lunch with the Queen.
Obama, who is on a three-day visit with his wife Michelle, is meeting PM David Cameron for talks.
Obama has told the Daily Telegraph being in the EU magnified Britain's influence across the world.
But London Mayor Boris Johnson called his view "hypocritical", describing the EU system as "alien" to US traditions.
Obama is now meeting Prime Minister David Cameron for talks at Downing Street.
Earlier the president and First Lady Michelle Obama attended a private lunch with the Queen and Duke of Edinburgh at Windsor Castle - the day after the Queen's 90th birthday celebrations.
The Duke and Duchess of Cambridge and Prince Harry will welcome the Obamas for dinner at Kensington Palace on Friday evening.
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. They claim the US "would never contemplate anything like the EU for itself".
In an article for the newspaper, President Obama acknowledged 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."
In response, Cameron tweeted: "The US is one of our closest allies. So it's important to hear Barack Obama on why we should remain in the EU."
BBC North America editor John Sopel said the president had not needed to make his intervention and could have been much more nuanced.
"That he has is a mark of the profound concern felt in Washington about the implications of a British departure from the EU," he said.
However, BBC political editor Laura Kuenssberg said a Brexit-supporting cabinet minister had stressed that Obama's view "was not the settled view in the USA. The Republicans don't agree and there is disquiet at his blatant meddling in UK politics".
The minister had suggested Ted Cruz supported Brexit, she added.
Speaking to the paper, Obama said that the US's relationship with the UK had been "forged as we spilt blood together on the battlefield".
He went on to say the UK had benefitted from being inside the EU in terms of jobs, trade and financial growth, and that it "magnifies" the UK's global influence.
"This kind of co-operation - 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.
Former US State Department spokesman James Rubin told BBC Breakfast the president had not offered any words of reassurance about Britain's future relationship with the US if it left the EU because "it won't be OK".
"We have a phrase in America: 'Friends don't let friends drive drunk,'" he said, adding that it would be "a big mistake for Britain to leave the EU and set asunder what has been a very successful relationship".
But Vote Leave's Boris Johnson said although he was a "big fan" of Obama, remaining in the EU is "clearly something we have a disagreement on".
He said: "America's a proud democracy built on principles of liberty. It is hypocritical for us to be told by America to embroil ourselves ever more deeply in a structure which would be absolutely alien to American traditions.
"I think most Americans would accept that there is something rum about asking us to subordinate our democracy in this way, when America would not dream in a million years of doing likewise."
Johnson originally criticised Obama in an article in the Sun but has since been criticised for making comments about the president's "part-Kenyan" ancestry.
Tory MP Iain Duncan Smith, who is also part of the Vote Leave campaign, echoed Johnson's comments, adding: "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."
Former British Army Commander Richard Kemp told the BBC Obama's comments on security were "diametrically opposite to the reality" and staying in the EU would be worse for UK's national security and for international security.
Obama's UK stay is part of a tour taking in Germany and Saudi Arabia, which he left on Thursday after having discussions with King Salman on issues including Iran, Syria, Yemen and the fight against so-called Islamic State militants.