David Cameron has been caught on camera talking about how the Queen “purred down the line” after he phoned her to say Scotland had voted no to independence.

The prime minister’s remarks suggesting the Queen was pleased with the result are a rare, albeit accidental, breach of the convention that the prime minister never speaks about his conversations with the monarch. It also jeopardises her traditional neutrality, which she maintained throughout the referendum campaign except when she was overheard telling a member of the public that she hoped people in Scotland would think carefully about the future.

Cameron’s exchange with Michael Bloomberg, the former New York mayor, was accidentally picked up by Sky News as they walked through an office in the businessman’s media empire.

“The definition of relief is being the prime minister of the United Kingdom and ringing the Queen and saying: ‘It’s alright, it’s OK’. That was something. She purred down the line.”

Part of the conversation is inaudible, but he was then recorded saying: “But it should never have been that close. It wasn’t in the end, but there was a time in the middle of the campaign when it felt …”

Cameron also joked about taking legal action against pollsters who suggested the two campaigns were neck and neck, when the final result saw 55% vote no to independence and 45% yes.

“I’ve said I want to find these polling companies and I want to sue them for my stomach ulcers because of what they put me through. It was very nervous moments,” he said.

It is the first time Cameron has been heard talking of how worried he was that the Better Together campaign might lose. Although it could have given the Conservatives an electoral advantage, backbenchers would have probably forced the prime minister to resign in the event of a yes vote.

In the final two weeks of the campaign, the Westminster leaders offered a faster package of devolution to Scotland and Cameron made an emotional plea for the union to stay together.

Downing Street declined to comment on the embarrassing gaffe, which is unlikely to have gone down well with Buckingham Palace.

Following the referendum result, the Queen said she believed Scotland would unite in a “spirit of mutual respect and support”, despite “strong feelings and contrasting emotions”

The statement, signed Elizabeth R, read: “After many months of discussion, debate, and careful thought, we now know the outcome of the referendum, and it is a result that all of us throughout the United Kingdom will respect ... Knowing the people of Scotland as I do, I have no doubt that Scots, like others throughout the United Kingdom, are able to express strongly held opinions before coming together again in a spirit of mutual respect and support, to work constructively for the future of Scotland and indeed all parts of this country.

“My family and I will do all we can to help and support you in this important task.“

She is understood to have watched the referendum debate with close interest. On the Friday of the result, she spoke to Cameron on the phone and issued her written statement in the afternoon.

It was thought that the monarch, who was praised by both sides during the campaign, believed that it was important to send a message of reconciliation after the heated debates.

The anti-independence camp believed it was a helpful intervention when the Queen’s only public remarks on the issue were overheard outside Crathie Kirk near her Balmoral estate in Aberdeenshire after the Sunday morning service. There was even speculation that the situation had been stage-managed by the palace as a very subtle hint about her desire for the union to stay together.

Before that, Nigel Farage, the Ukip leader, had called on her to intervene in the event of very tight polls. He told LBC 97.3 that it “might be handy” if she could make her views known given what was at stake.