He was caught on camera making the remarks to Queen Elizabeth II and Archbishop of Canterbury Justin Welby at an event at Buckingham Palace.
"We've got some leaders of some fantastically corrupt countries coming to Britain," Cameron said, referring to the anti-corruption summit he is hosting on Thursday.
"Nigeria and Afghanistan, possibly the two most corrupt countries in the world," he said.
Welby, who worked as an oil executive in West Africa before joining the church and who has also undertaken conflict resolution work in Nigeria, noted that "this particular president is actually not corrupt".
"He's really trying," Cameron agreed, and the queen noted to Welby: "He is trying, isn't he?"
It was not clear to whom they were referring, but Nigerian President Muhammadu Buhari and Afghanistan's President Ashraf Ghani are both due to attend the summit.
Buhari has embarked on a widespread anti-corruption campaign since taking office one year ago, and is due to give a speech on the issue in London on Wednesday.
In Afghanistan, Ghani also made a promise to rein in runaway corruption when he was elected in 2014.
Cobus de Swardt, managing director of global advocacy group Transparency International, said: "There is no doubt that historically, Nigeria and Afghanistan have had very high levels of corruption, and that continues to this day.
"But the leaders of those countries have sent strong signals that they want things to change, and the London Anti-Corruption Summit creates an opportunity for all the countries present to sign up to a new era."
Conversations between the prime minister and the queen are normally confidential, and Cameron had to apologise after revealing the monarch "purred" when she was told Scotland had voted against independence in 2014.
On Tuesday, a Downing Street spokeswoman said it would not comment on a private conversation, but noted that both Buhari and Ghani "have acknowledged the scale of the corruption challenge they face in their countries".
She revealed that in a collection of essays to be published at the summit, Ghani writes that Afghanistan is "one of the most corrupt countries on Earth".
Buhari, for his part, writes that corruption became a "way of life" under "supposedly accountable democratic governments", the spokeswoman said.
She concluded: "Both leaders have been invited to the summit because they are driving the fight against corruption in their countries. The UK stands shoulder to shoulder with them as they do so."