Barack Obama has intervened in the debate on Scottish independence, saying that the United States has a deep interest in ensuring the UK remains "strong, robust and united".

In an unexpected intervention, the president said during a joint press conference with David Cameron on Thursday that he thought the UK "had worked pretty well," and had been an extraordinary and effective partner to the US.

Obama stressed twice during the press conference at the G7 meeting in Brussels that the decision on independence was "up to the people of Scotland", but he made it clear that he wanted to see a no vote in September's referendum.

"I would say that the United Kingdom has been an extraordinary partner to us. From the outside at least, it looks like things have worked pretty well," he said.

"And we obviously have a deep interest in making sure that one of the closest allies that we will ever have remains a strong, robust, united and effective partner. But ultimately these are decisions that are to be made by the folks there."

His remarks end months of speculation about the US stance on the referendum. Madeleine Albright, the former US secretary of state and Obama campaign fundraiser, observed 18 months ago that "fragmentation does not help" the US and the EU, but serving US diplomats, including the US ambassador to London, Matthew Barzun, have studiously avoided making any direct comment on the issue.

Privately, however, figures in the Obama administration have expressed fears about the significant impact on US interests if the UK's influence and status in Nato, the UN security council and the EU were weakened by Scotland's independence and the loss of Trident nuclear submarines on the Clyde.

Obama's remarks are a setback for Alex Salmond's government and the wider independence movement because of the US president's influence on centre-left public opinion, at a time when opinion polls show a narrowing gap between yes and no votes in the referendum. Foreign diplomats in the UK have warned their governments that a yes vote is now more likely than before.

The Scottish National party has borrowed heavily from Obama's first election campaign, using slogans and complex campaigning techniques in its past election successes and the current independence campaign.

Salmond appeared to chide Obama by observing immediately that the US president agreed the decision on Scotland's future was for Scottish voters, and reminding Obama that Scotland was "deeply fortunate" that September's referendum was being conducted "in a deeply democratic way", unlike the US war for independence nearly 250 years ago.

"An independent Scotland will mean that America has two great friends and allies here rather than one," Salmond added, before deliberately repeating the Obama campaign slogan borrowed by the SNP.

"We are focused on securing a vote for independence this September and making Scotland a land of opportunity – and our message to the people of Scotland in the campaign in the months ahead is: 'Yes We Can'," he said.

In a move calculated to allow Obama's remarks to circulate without polarising the debate, no UK government ministers commented directly on his intervention. Douglas Alexander, the shadow foreign secretary, said Obama's "clear statement of support for the UK staying together will resonate with many of us here in Scotland.

"As a global statesman President Obama understands that interdependence is a defining feature of our modern world, and that building bridges, not putting up new barriers, is the challenge of our generation."