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," Mr Cameron said.
Nigeria's president, who came to power last year vowing to fight corruption, said he was "shocked" by the remarks.
After Mr 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.
On the face of it, it is perhaps one of the most undiplomatic things a prime minister could say - to describe two countries as fantastically corrupt just hours before their leaders visit Britain.
The prime minister's remarks were outspoken and unguarded but they were not untrue. Both Afghanistan and Nigeria come high on lists of the world's most corrupt nations.
And later in the conversation, the prime minister agreed with the Archbishop of Canterbury that President Buhari of Nigeria is not corrupt himself and is trying very hard to tackle the problem.
A Downing Street spokesman noted both men had written openly about the subject in a collection of essays being published this week.
So this was a truthful gaffe, another moment when the prime minister was caught on camera saying something ostensibly embarrassing.
Labour said Mr Cameron had egg on his face. But as Downing Street acknowledged, the cameras were very close to the prime minister and his anti-corruption summit is now very firmly in the headlines.
Afghanistan was ranked at 167, ahead of only Somalia and North Korea, in Transparency International's 2015 corruption perception index . 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, Mr Buhari said his government was deeply "shocked and embarrassed" by the comments.
Speaking through his spokesman, he suggested that Mr Cameron must be referring to Nigeria's past notoriety for corruption before his coming to power last year.
Labour MP Wes Streeting said Mr Cameron had "egg on his face" and for all the PM's rhetoric about tackling corruption, he had failed so far to get all the UK's crown dependencies and overseas territories to sign up to new transparency rules on corporate ownership.
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, Mr 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."