GettyImages-523218812
U.S. President Barack Obama speaks during a press conference at the Foreign and Commonwealth Office in central London on April, 22, 2016, with British Prime Minister David Cameron. Getty

U.S. President Barack Obama said Friday that if Britain left the European Union there may eventually be a commerce agreement between the two countries but that Britain would be at the back of the queue for a trade deal.

Speaking to reporters in London alongside Prime Minister David Cameron, Obama said having access to a big market like the EU is hugely efficient.

During his visit to the U.K., Obama has appealed directly to British voters to remain in the European Union, saying membership has magnified Britain's place in the world and made the bloc stronger and more outward-looking.

Obama, who opinion polls show is popular in Britain, applauded Britain's EU membership, which he said has helped make the world freer, richer and better able to tackle everything from migration to terrorism.

Invoking the interlinked history of the United States and Britain, and the tens of thousands of Americans lying in European war graves, Obama implored voters to weigh the benefits of membership ahead of a June 23 referendum.

"The European Union doesn't moderate British influence — it magnifies it," Obama wrote in the Daily Telegraph, a Euroskeptic British newspaper.

"As your friend, I tell you that the EU makes Britain even greater," the headline of Obama's article read.

His remarks, which led television news broadcasts in Britain, undercut one of the most passionate arguments of the opponents of EU membership: that Britain could prosper on an equal basis with global powers such as the United States.

A spokeswoman for Prime Minister David Cameron welcomed Obama's intervention, but the president's comments drew scorn from opponents of Britain's EU membership.

New York-born London Mayor Boris Johnson, a leader of the Out campaign, who hints he wants Cameron's job, derided Obama's arguments in a newspaper column that referred to "the part-Kenyan president's ancestral dislike of the British empire."

John McDonnell, the opposition Labour Party's finance policy chief, called Johnson's remarks "dog whistle racism."

The White House declined to comment, and a spokesman for Johnson did not respond to requests for comment.