Diane Abbott, the shadow health minister, has apologised after posting a Twitter comment about white people that led to her being accused of racism.

"I understand people have interpreted my comments as making generalisations about white people," Abbott, who stood for the Labour leadership in 2010, said. "I do not believe in doing that. I apologise for any offence caused."

She was ordered to apologise by the Labour leader, Ed Miliband. Miliband resisted a call from a Conservative MP to sack her, but her apology coincided with Labour issuing a statement disowning her contentious remark.

The row began when Abbott, who has more than 26,000 Twitter followers, became involved in a discussion with Bim Adewunmi, triggered by the Stephen Lawrence case, on Wednesday.

Adewunmi said she objected to the way in which the term the "black community" was used as a generalisation.

Abbott responded with a series of messages. "I understand the cultural point you are making. But you are playing into a 'divide and rule' agenda," she said. Then she added: "White people love playing 'divide & rule' We should not play their game #tacticasoldascolonialism."

And finally she said: "Ethnic communities that show more public solidarity & unity than black people do much better #dontwashdirtylineninpublic."

Although her comments were addressed to Adewunmi, Abbott did not use the Twitter direct message facility, which keeps messages private. As a result, they were available for anyone to read.

On Thursday, as the remark circulated widely on Twitter, Nadim Zahawi, the MP for Stratford-on-Avon, accused Abbott of racism.

"A healthy society should not tolerate any form of racism. DAbbott should apologise and resign or EdM must sack her," he wrote on Twitter.

Nick Clegg, the deputy prime minister, said Abbott's comment was "crass and stupid" and that she should apologise.

On Thursday morning, Abbott was playing down the significance of the row. In a post on Twitter, she wrote: "Tweet taken out of context. Refers to nature of 19th century European colonialism. Bit much to get into 140 characters."

She used the same phrase later when asked about the row in an interview with Sky News, saying: "I think the tweet was taken out of context and some people have interpreted it maliciously."

But, as she was speaking to Sky News, she was filmed taking a call on her mobile phone. The call was from Miliband. According to party sources, she was given a "severe dressing down" and ordered to apologise unreservedly.

"If she believed the interpretation that was being put upon what she said, she would have been out," a source said.

A Labour party spokesman said: "We disagree with Diane's tweet. It is wrong to make sweeping generalisations about any race, creed, or culture. The Labour party has always campaigned against such behaviour – and so has Diane Abbott."

Abbott received backing from the former Labour MP George Galloway. "Diane Abbott has been my friend for 25 years; only the obtuse would think her a 'racist'," Galloway posted on Twitter.