Nick Clegg has attacked the "unpleasant, careless elitism" of Boris Johnson and his remarks about IQ, and accused him of talking about people as if they were dogs.

The deputy prime minister laid into Johnson after the Conservative London mayor mocked the 16% "of our species" with an IQ below 85 and called for more to be done to help the 2% of the population who have an IQ above 130.

Johnson made the remarks during a speech in honour of Margaret Thatcher, declaring that inequality was essential to foster "the spirit of envy" and hailing greed as a "valuable spur to economic activity".

In a furious response, Clegg said Johnson's viewpoint was "completely anathema" to him, as it suggested society should give up on some people who were never going to do well. This is a "dispiriting message to people trying to get on in life", he said.

"I don't agree with Boris Johnson on this. Much as he is a funny and engaging guy, I have to say these comments reveal a fairly unpleasant, careless elitism that somehow suggests we should give up on a whole swath of fellow citizens," Clegg told LBC 97.3 radio.

"To talk about us as if we are a sort of breed of dogs, a species I think he calls it … the danger is if you start taking such a deterministic view of people because they have got a number attached to them, in this case an IQ number, they are not going to rise to the top of the cornflake packet, that is complete anathema to everything I've always stood for in politics."

Clegg said he believed children developed at different paces and should have access to a culture of opportunity, aspiration and hard work.

"Our job is surely in politics not simply to say we are going to hive off one group of people and put them in one category and kind of basically say they are parked, there's not much we can do … These things are precisely not about treating society like a great big cake saying we're not going to do much about that slice but we are going to concentrate on that slice."

David Lammy, the Tottenham MP who is thinking about running as Labour's London mayoral candidate in 2016, described the remarks as an insult to people in the capital on low wages.

"I don't think that's just careless. I think it's an insult," he told BBC Radio 4's World at One. "It's an insult to cleaners in London, to people who are home carers in London, people who are minimum wage, giving them the suggestion that they are sort of bottom of the cornflake packet. That's not the sort of society that I thought we wanted to live in, particularly when the mayor has supported the London living wage, which is about saying that we all ought to be in this together.

"There is nothing wrong with aspiration, with enterprise and indeed with competition, but not when it's at the expense of other people and that's what we saw from the banking crisis.

"It's extraordinary for a mayor, who should be for all of London, to think it's all right to glorify greed – a greed that has brought a banking collapse and caused misery and hardship to many Londoners, particularly to young people who can't get on the housing ladder."

Johnson's most provocative comments came when he talked about the relevance of IQ to equality.

The mayor said: "Whatever you may think of the value of IQ tests it is surely relevant to a conversation about equality that as many as 16% of our species have an IQ below 85 while about 2% …"

Johnson departed from the text of his speech to ask whether anyone in his City audience had a low IQ: "Over 16% anyone? Put up your hands."

He then resumed his speech to talk about the 2% who have an IQ above 130, telling the Centre for Policy Studies thinktank: "The harder you shake the pack the easier it will be for some cornflakes to get to the top."

Johnson also aligned himself with what were seen as the excesses of 1980s Thatcherism as he said: "I stress – I don't believe that economic equality is possible; indeed some measure of inequality is essential for the spirit of envy and keeping up with the Joneses that is, like greed, a valuable spur to economic activity."

He made clear, however, that Thatcherism needed to be updated for the 21st century.

"I hope there is no return to the spirit of loadsamoney heartlessness – figuratively riffling banknotes under the noses of the homeless – and I hope that this time the Gordon Gekkos of London are conspicuous not just for their greed – valid motivator though greed may be for economic progress – as for what they give and do for the rest of the population, many of whom have experienced real falls in their incomes over the last five years."

Johnson is assessing when to return to Westminster to ensure he is in a strong place to challenge for the Conservative leadership when the prime minister stands down. His speech appeared to be an attempt to reach out to the Tory right by calling for new grammar schools and warning the accession of Romania to the EU means London can do nothing to stop the "entire population of Transylvania" from pitching their tents in Marble Arch.