The prime minister's comments came as he was speaking to the Archbishop of Canterbury Justin Welby, Conservative cabinet minister Chris Grayling as well as the Queen during a reception in Buckingham Palace to mark her 90th birthday.
In footage filmed by ITN, Cameron tells the Queen: "We have got some leaders of some fantastically corrupt countries coming to Britain.
"We've got Nigeria and Afghanistan, possibly the two most corrupt countries in the world."
The Queen did not reply to the prime minister. But Welby interjected: "But this particular president is actually not corrupt."
It is not clear if Cameron knew he was being recorded. But the prime minister's spokesman said: "The cameras are very close to him. There are multiple cameras in the room."
Bercow, the Speaker of the Commons, joked to Cameron: "They are coming at their own expense one assumes?"
"Everything has to be open," the prime minister replied. "There are no sort of closed-door sessions. Everything has to be in front of the press. It's going to be... It could be quite interesting."
Cameron is hosting world leaders at an anti-corruption summit in London this week.
Among the presidents due to attend the summit are Ashraf Ghani of Afghanistan and Muhammadu Buhari of Nigeria.
According to Transparency International, Afghanistan is the third most corrupt country in the world. Nigeria is ranked as the 32 most corrupt.
A spokesman for the prime minister said both President Buhari of Nigeria and President Ghani of Afghanistan "have acknowledged the scale of the corruption challenge they face in their countries".
"In a collection of essays to be published on the day of the summit, President Ghani writes that Afghanistan is 'one of the most corrupt countries on earth', while President Buhari writes that corruption became a 'way of life' in his country under 'supposedly accountable democratic governments'," the spokesman said.
Put to No.10 that the Queen, as well as the presidents, would have been embarrassed by the remarks, the spokesman said: "He's invited them because they have publicly acknowledged they have a problem with corruption.
"Both the Presidents have acknowledged in the collection of essays that are being published alongside the summit that there is an issue with corruption in their countries. That is why they have been invited."
Asked if the PM had known about the comments, No10 said: "The PM has done the foreword to the collection of essays, [which] he himself has been involved in collecting."
It is not the first time Cameron has been caught on film. In 2014, Sky News filmed him telling Mike Bloomberg the Queen had "purred down the line" after he phoned her to say Scotland had voted against independence.
Labour MP Wes Streeting said today: "This is another gaffe from the PM - you’d hope he’d have learned his lesson when it comes to off the record comments and the Queen but sadly not.
"The fact that David Cameron has egg on his face shouldn’t deflect from the more serious issue: for all his talk about corruption he’s failing to act.
"If the PM really is serious about tackling corruption at the summit this week he needs to get his own house in order and make good on his promise to deliver public registers of beneficial ownership for the UK crown dependencies and overseas territories."
Suggested For You
Get top stories and blog posts emailed to me each day. Newsletters may offer personalized content or advertisements. Learn more