The advert features a bullet with the words “Uhh dad I’m gay” flying towards a heart made of china.
The advert, on a pink background, includes the tagline “You need a strong heart today” near the Flora logo.
Flora, owned by Unilever, has long promoted its margarine as helping consumers maintain a healthy heart.
“This advert was prepared by an external agency in South Africa
“The advert is offensive and unacceptable and we have put an immediate stop to it.”
UK-based gay rights group Stonewall said it welcomed the withdrawal of the advert.
It had earlier described the advert as “offensive and inappropriate”.
“Perhaps Flora should have a chat with their Unilever colleagues, Ben & Jerry’s, about how best to produce gay-friendly advertising fit for the 21st Century,” it said.
Last month, Ben & Jerry’s, a Unilever-owned ice-cream maker, came out in support of same-sex marriages in Australia, renaming its Cookie Dough flavour to “I Dough, I Dough”.
International advertising firm Lowe and Partners, which designed the controversial advert, said it was “very sorry”.
“I would like to unreservedly apologise for this campaign and the unintended offence it has regrettably caused,” the firm’s Johannesburg managing director Sarah Dexter said.
“We have requested the immediate removal of this work from all media,” she added.
A second advert promoting Flora shows a glass heart about to be hit with a bullet, featuring the words “Kama Sutra page 48”.
South Africa has one of the most liberal constitutions in the world, recognising gay rights.
However, homophobia is rife and many gay and lesbian people have been attacked.