Mr McGrath responded to "a silly and hostile suggestion", Mr Johnson said
An aide to London Mayor Boris Johnson has resigned after making a comment to a reporter which sparked a race row.
Responding to a claim that some black people might leave the UK if Mr Johnson became mayor, James McGrath said: "Let them go if they don't like it here."
Mr McGrath said his remark to a journalist from the-latest.com website had been taken out of context.
Mr Johnson said he knew Mr McGrath was "not a racist", but the remarks made it "impossible" for him to keep his job.
Conservative leader David Cameron, who worked with Mr McGrath before the 2005 election, backed Mr Johnson's action.
He said Mr McGrath was not a racist and was a "good person" but his comments were a "lapse of judgement" - and in politics one had to "face the consequences".
Mr McGrath, a 34-year-old Australian who has worked for the Conservative Party for seven years, was appointed director of political strategy at City Hall after Mr Johnson became mayor last month.
Reporter Marc Wadsworth said that Mr McGrath made the comments to him when he pointed out a critical piece in a newspaper during Mr Johnson's election campaign.
David Cameron on Mr McGrath's comments
In his online article he writes: "I pointed out to him a critical comment of Voice columnist Darcus Howe that the election of 'Boris Johnson, a right-wing Conservative, might just trigger off a mass exodus of older Caribbean migrants back to our homelands'.
"He retorted: 'Well, let them go if they don't like it here.' McGrath dismissed Mr Howe as 'shrill'."
Mr McGrath then wrote a comment on the website in reply: "The columnist suggested that older people from the Caribbean might migrate back to their homelands if Boris Johnson became Mayor.
"I felt that this suggestion was ridiculous and intended as a slur and responded by saying with words to effect of 'let people go if they don't like it here'.
"To imply that I meant that all black people who didn't support Boris Johnson should leave the country is utterly absurd and incorrect. And I would ask please that this insinuation is immediately retracted."
In a statement Boris Johnson said: "It is with great regret this evening that I have accepted the resignation of my political adviser, James McGrath.
"Unfortunately, his remarks in a conversation with an internet journalist, published this weekend, made it impossible for him to continue in that role.
"James is not a racist. I know that. But his response to a silly and hostile suggestion put to him by Marc Wadsworth, allowed doubts to be raised about that commitment.
"I wish James well in the future, thank him for his contribution and urge everyone not to misrepresent his view or misinterpret his intentions any further."
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.