David Cameron has described Nigeria and Afghanistan as "fantastically corrupt" in a conversation with the Queen.
The PM was talking about this week's anti-corruption summit in London.
"We've got some leaders of some fantastically corrupt countries coming to Britain... Nigeria and Afghanistan, possibly the two most corrupt countries in the world," he was overheard saying.
Nigerian President Muhammadu Buhari, elected last year after vowing to fight corruption, said he was "shocked".
And a senior Afghan official said the characterisation was "unfair".
After Cameron's comments, Archbishop of Canterbury Justin Welby intervened to say: "But this particular president is not corrupt... he's trying very hard," before Speaker John Bercow said: "They are coming at their own expense, one assumes?"
The conversation took place at Buckingham Palace at an event to mark the Queen's 90th birthday, attended by political leaders and other public figures.
At a garden party later on Tuesday, the Queen herself was caught on camera making unguarded comments about the Chinese government.
She told a senior police officer that she had heard the Chinese had been very rude to Britain's ambassador to China during President Xi's state visit last year. The Queen also agreed that the Chinese state visit had been a testing time for the police and told the officer it was "bad luck" that she had been in charge of security at the time.
In Transparency International's 2015 corruption perception index, Afghanistan was ranked at 167, ahead of only Somalia and North Korea, Nigeria was at 136.
With his remark, the archbishop was believed to have been referring to Nigeria's President Muhammadu Buhari, who won elections last year promising to fight widespread corruption.
In response, Buhari said his government was deeply "shocked and embarrassed" by the PM's comments. Speaking through his spokesman, he suggested that Cameron must be referring to Nigeria's past notoriety for corruption before his coming to power last year.
The Afghan embassy in London said tackling corruption was one of President Ghani's top priorities and "bold" action had been taken.
"We have made important progress in fighting systematic capture in major national procurement contracts and are making progress on addressing institutional issues as well as issues related to impunity... Therefore calling Afghanistan in that way is unfair."
'Egg on face'
No 10 said the presidents of Nigeria and Afghanistan had "acknowledged the scale of the corruption challenge they face in their countries".
The government will host world and business leaders at the summit on Thursday in London, aiming to "galvanise a global response to tackle corruption". Speaking ahead of the summit, Cameron said: "For too long there has been a taboo about tackling this issue head-on.
"The summit will change that. Together we will push the fight against corruption to the top of the international agenda where it belongs."
But Labour said a Tory government "hosting an anti-corruption summit is like putting the fox in charge of the chicken coop".
"The government is refusing to take meaningful action to close Britain's constellation of tax havens, which together constitute the largest financial secrecy network in the world," said shadow international development secretary Diane Abbott.
Transparency International said the UK's record was mixed and concrete action was needed on tax evasion and secrecy in the wake of the Panama Papers disclosures, stopping tainted firms from bidding for public contracts and protecting whistleblowers who expose corruption.
Last year Cameron was recorded talking about Yorkshire people "hating each other" - and he was previously caught revealing how the Queen "purred" with pleasure when he told her the Scottish independence referendum result.