President Obama descends to the tarmac from Air Force One after landing at Stansted Airport in London on Thursday. (Jim Watson/AFP/Getty Images)

President Obama weighed in on one of the United Kingdom’s most contentious political issues Friday, urging Britain to remain part of the European Union and warning that a withdrawal would diminish British influence on the world stage.

The president made his case at a news conference with Prime Minister David Cameron at his side and in a surprisingly frank editorial in London’s Daily Telegraph.

“The European Union doesn’t moderate British influence — it magnifies it,” Obama wrote. “A strong Europe is not a threat to Britain’s global leadership; it enhances Britain’s global leadership.”

The editorial and the news conference with Cameron plunged Obama into the middle of an emotional debate inside Britain only two months before the country’s June 23 referendum on E.U. membership.

It is highly unusual for a U.S. president to weigh in on the internal affairs of an ally so close to voters going to the polls, a fact that Obama acknowledged in his editorial. “I realize that there’s been considerable speculation — and some controversy — about the timing of my visit,” he wrote. But Obama argued that the “special relationship” between the United States and Britain demanded unusual honesty.

Obama sounded dire warnings about the consequences of a British exit from the European Union that to many may have sounded like threats.

If Britain severed ties with the E.U., Obama said, it would be at the “back of the queue” for a trade deal with America. “There might be a U.K.-U.S. trade agreement, but it’s not going to happen anytime soon because our focus is in negotiating with a big block, the European Union,” Obama said.

In other moments the president tried appeals to Britons’ better angels, saying he understood the instinct at a time of worries about terrorism and massive refu­gee flows to want to “pull up the drawbridge” on the rest of the world’s problems.

But he expressed confidence that citizens in Britain and the United States would rise above those baser fears. “The ties that bind Europe together are ultimately much stronger than the forces that are trying to pull them apart,” Obama said.

Even before Obama arrived in Britain, Boris Johnson, London’s mayor, accused the president of hypocrisy on the issue. Johnson, who is in favor of leaving the European Union, told the BBC that the United States “wouldn’t dream of sharing [its] sovereignty.”

Obama, who came to London from Saudi Arabia, marked the beginning a three-day visit to Europe at an especially difficult moment for the continent, which faces a slow economy, refugees pouring across its borders and a growing terror threat.

He is expected on Monday to deliver a major speech in Germany on the problems facing Europe, its critical role in the world and its path forward.

Obama has been critical of America’s European allies, suggesting recently in an interview with the Atlantic that Cameron and his European partners became “distracted” after the NATO-led intervention in Libya and didn’t do enough to bring stability to the country. He has suggested that some European countries are “free riders” for depending too heavily on the United States to provide for their defense.

Despite those criticisms, Obama remains very popular among the British people and throughout Europe. His decision to visit London so close to the referendum came at the request of Cameron, who has been a forceful and, of late, more embattled advocate for remaining in the 28-nation bloc.

Cameron spoke repeatedly of his respect for Obama and emphasized that the president was acting on his own accord to preserve American interests and strengthen the special relationship that the United States and Britain share.

“I don’t have some special power over the president of the United States,” Cameron said. “To me it is simple: stronger Britain, stronger special relationship. That is in our interests, and that is in the interest of the U.S. as well.”

Even though Obama has been outspoken in his support for Britain staying in the European Union, analysts urged him to tread lightly on his visit. “This is an emotionally charged discussion, and it really does not respond to calm, rational logic,” said Heather Conley, a senior European analyst at the Center for Strategic and International Studies in Washington.

Conley said the president should “weigh in” but avoid being part of the story. “Do not exacerbate the tensions surrounding the referendum,” she warned.

Prior to Obama’s arrival in London, senior administration officials suggested that Obama would heed that advice.

“His approach will be that if he’s asked his view as a friend, he will offer it, but he’ll make very clear that this is a matter that the British people themselves will decide,” Ben Rhodes, a deputy national security adviser, told reporters before the trip.

With his editorial in the Daily Telegraph, Obama seems to have decided that the stakes were too high for him to take a lower-profile approach.

Obama chose a Conservative-supporting newspaper, which hasn’t taken a stand on the E.U. referendum, to appeal to Conservatives and others seen as crucial swing voters in the referendum.

Obama praised Britain’s leadership in helping to secure a major global agreement to address climate change last year and its efforts to reach a deal with Iran to prevent Tehran from acquiring a nuclear weapon.

Such international efforts, with the European Union playing a leading role, are essential to peace, prosperity and international order, Obama wrote.

“Today, we face tests to this order — terrorism and aggression; migration and economic headwinds — challenges that can only be met if the United States and the United Kingdom can rely on one another, on our special relationship, and on the partnerships that lead to progress,” Obama wrote in the Telegraph.

The terrorist attacks in Paris and Brussels, in particular, have exposed big gaps in intelligence sharing among European countries. Obama argued that a unified counterterrorism partnership that spanned Europe is essential to keeping the continent safe.

“Now is a time for friends and allies to stick together,” he added.

The president had lunch Friday with Queen Elizabeth II at Windsor Castle to celebrate her 90th birthday, which Obama jokingly suggested was his real reason for his visit.

“I confess: I do want to wish Her Majesty a happy birthday in person,” he wrote.