People who took tablets known as proton pump inhibitors (PPIs) or histamine antagonists (H2RAs) were more likely to lack enough vitamin B12 for good health.
Medication used to treat stomach ulcers may cause potentially harmful vitamin B12 deficiency, say experts.
A US study of 200,000 people in the Journal of the American Medical Association found the link.
Left untreated, B12 deficiency can lead to dementia and neurological problems.
The study authors say doctors should still prescribe these medicines, but that they should weigh possible harms against any benefits in patients who need the drugs for prolonged periods of time.
More investigations are needed to fully evaluate the risk which appears to be in people who take these medications for two or more years, they say.
LINK NOT PROOF
The Kaiser Permanente researchers found that the link with B12 deficiency increased with dose and was stronger in women and younger age groups.
But the overall risk was still low.
PPIs and H2RAs are commonly prescribed for patients with symptoms of stomach ulcers such as heartburn and indigestion.
The tablets are also widely available to buy without a prescription, 'over-the-counter' at pharmacies.
They work by reducing the amount of acid made by your stomach.
Stomach acid is needed for us to absorb vitamin B12 from our food, such as meat, fish and dairy.
If identified, most cases of B12 deficiency can be easily treated by giving supplements or an injection of vitamin B12.
But symptoms, such as lethargy, can be vague and overlooked.
Prof Mark Pritchard of the British Society of Gastroenterology said people should not be concerned by the findings.
"Only patients who had taken these tablets for more than two years were at risk and only a minority of patients on long-term proton pump inhibitors showed evidence of vitamin B12 deficiency."
He said people taking ulcer medications could ask their GP for a simple blood test to measure vitamin B12 levels if they are worried.