The gut of Drosophila melanogaster includes a proximal acidic region (~pH 2), however the genome lacks the H(+)/K(+) ATPase characteristic of the mammalian gastric parietal cell, and the molecular mechanisms of acid generation are poorly understood. Here, we show that maintenance of the low pH of the acidic region is dependent on H(+) V-ATPase, together with carbonic anhydrase and five further transporters or channels that mediate K(+), Cl(-) and HCO3(-) transport. Abrogation of the low pH did not influence larval survival under standard laboratory conditions, but was deleterious for insects subjected to high Na(+) or K(+) load. Insects with elevated pH in the acidic region displayed increased susceptibility to Pseudomonas pathogens and increased abundance of key members of the gut microbiota (Acetobacter and Lactobacillus), suggesting that the acidic region has bacteriostatic or bacteriocidal activity. Conversely, the pH of the acidic region was significantly reduced in germ-free Drosophila, indicative of a role of the gut bacteria in shaping the pH conditions of the gut. These results demonstrate that the acidic gut region protects the insect and gut microbiome from pathological disruption, and shed light on the mechanisms by which low pH can be maintained in the absence of H(+), K(+) ATPase.