The pharmacy chains Walgreens, Rite Aid and CVS have moved to stop selling the heartburn medicine Zantac and its generic versions after the Food and Drug Administration warned this month that it had detected low levels of a cancer-causing chemical in samples of the drug.

A Walgreens spokesman said in a statement on Monday that the company had pulled the drug from its shelves “while the FDA continues its review of the products.” A Rite Aid spokesman said the company was “in the process of removing Zantac and generic versions sold under the Rite Aid name from its shelves.”

Walgreens and CVS, which announced its move on Saturday, both noted that the drug, which is known as ranitidine, has not been recalled. The companies said customers who had bought the products could return them for a refund.

The F.D.A. has said it is investigating the source of the contamination as well as the risk to patients, recommending that they talk to their doctors and that those who take over-the-counter versions consider switching to a different medication.