Background. Strategies based on screening for Helicobacter pylori to manage dyspeptic patients in primary care have been proposed. but the clinical consequences are unclear. We did a randomised trial to assess the efficacy and safety of a test-and-eradicate strategy compared with prompt endoscopy in the management of patients with dyspepsia. Methods. 500 patients presenting in primary care with dyspepsia (≥ 2 weeks of epigastric pain, no alarm symptoms) were assigned H pylori testing plus eradication therapy or endoscopy. Symptoms, quality of life, patients' satisfaction, and use of resources were recorded during 1 year of follow-up. Findings. 250 patients were assigned test-and-eradicate, and 250 prompt endoscopy. The median age was 45 years and 28% were H pylori infected. 1 year follow-up was completed by 447 patients. We found no differences in symptoms between the two groups (median registered days without dyspeptic symptoms = 0.63 [IQR 0.27-0.81] in the test-and-eradicate group vs 0.67 [0.36-0.86] in the prompt endoscopy group; mean difference 0.04 [95% CI -0.01-0.10], p = 0.12). Nor did we find any difference in quality of life or numbers of sick-leave days, visits to general practitioners, or hospital admissions. In the test-and-eradicate group, 27 (12%) of the patients were dissatisfied with management, compared with eight (4%) in the endoscopy group (p = 0.013). After 1 year, the use of endoscopies in the test-and-eradicate group was 0.40 times (95% CI 0.31-0.51) the use in the endoscopy group, the use of H pylori tests increased by a factor of 8.1 (5.7-13.1), the use of eradication treatments increased by a factor of 1.5 (0.9-2.7), and the use of proton-pump inhibitors was 0.89 (0.59-1.33) times the use in the endoscopy group. 43 (91% [80-98%]) of 47 peptic-ulcer patients would have been identified by endoscopy or treated by eradication therapy. Interpretation. A H pylori test-and-eradicate strategy is as efficient and safe as prompt endoscopy for management of dyspeptic patients in primary care, although fewer patients are satisfied with their treatment.