"We have got the Nigerians - actually we have got some leaders of some fantastically corrupt countries coming to Britain."
Cameron went on: "Nigeria and Afghanistan - possibly two of the most corrupt countries in the world."
The Queen did not respond to Cameron's comment but the Archbishop of Canterbury Justin Welby who was near the pair said: "But this particular president is actually not corrupt."
According to one account, a bystander joked to Cameron: "They are coming at their own expense one assumes?"
Cameron replied: "Everything has to be open. 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."
There was speculation in Westminster that Cameron could have made the remarks near the cameras in a bid to attract publicity for the summit.
Number 10 admitted the Prime Minister was aware he was being filmed at the time he spoke, saying: "The cameras were very close to him. There were multiple cameras in the room."
But Conservative MPs who are critics of the size of the aid budget seized on the admission, pointing out that in 2014 Nigeria and Afghanistan received £435 million in aid from the UK.
Andrew Bridgen MP said the payments to the two countries had to stop "because it's like offering a bottle of whisky to an alcoholic, they need to clean up their act first".
He added: "There should be a DfiD list of corrupt regimes that don't get aid and list should be publicised to but pressure on these corrupt regimes."
Philip Davies, another critical Tory MP, added: "I am sure the Prime Minister is right about these countries - I have got no doubt he is right about them.
"And so it is absolutely unforgivable that we are giving so much British taxpayers' money that he knows himself are corrupt."
Nigeria's President Muhammadu Buhari and Afghan President Afghan President Ashraf Ghani, who are both planning to attend the summit, have acknowledged corruption in their countries and have pledged to clean it up.
Afghanistan is 166th, second-from-bottom, in campaign group Transparency International's latest Corruption Perceptions Index, an annual ranking of countries. Nigeria is 136th in the index.
It emerged this week that Nigerian President Muhammadu Buhari had spent £150,000 educating his daughter Zahra, a Surrey University student.
Cameron's comments threatened to become a diplomatic incident, when Buhari said his Government was deeply "shocked and embarrassed" by the comments.
Speaking through his spokesman to the BBC he said Cameron must be referring to Nigeria's past notoriety for corruption before his coming to power last year
A Number 10 spokesman said that "British aid money does not go directly to the Nigerian or Afghan governments" and the UK was not paying for delegations to attend the summit.
He added: "We have a zero tolerance approach to corruption and have rigorous checks in place to protect taxpayers' money and take firm action if it is misused."
The Queen met Cameron and other political leaders from both the Lords and the Commons at Buckingham Palace to mark the her 90th birthday.
Labour leader Jeremy Corbyn missed the engagement to attend a family funeral and wrote to the Queen to explain his absence.
Cameron's gaffe is not the first time he has been caught on film. In 2014, he was filmed telling New York's mayor that the Queen had "purred down the line" after he had called her to say Scotland had rejected independence.