The coffee berry borer (Hypothenemus hampei) is the most devastating insect pest of coffee worldwide with its infestations decreasing crop yield by up to 80%. Caffeine is an alkaloid that can be toxic to insects and is hypothesized to act as a defence mechanism to inhibit herbivory. Here we show that caffeine is degraded in the gut of H. hampei, and that experimental inactivation of the gut microbiota eliminates this activity. We demonstrate that gut microbiota in H. hampei specimens from seven major coffee-producing countries and laboratory-reared colonies share a core of microorganisms. Globally ubiquitous members of the gut microbiota, including prominent Pseudomonas species, subsist on caffeine as a sole source of carbon and nitrogen. Pseudomonas caffeine demethylase genes are expressed in vivo in the gut of H. hampei, and re-inoculation of antibiotic-treated insects with an isolated Pseudomonas strain reinstates caffeine-degradation ability confirming their key role.