Horizontal gene transfer (HGT) involves the nonsexual transmission of genetic material across species boundaries. Although often detected in prokaryotes, examples of HGT involving animals are relatively rare, and any evolutionary advantage conferred to the recipient is typically obscure. We identified a gene (HhMAN1) from the coffee berry borer beetle, Hypothenemus hampei, a devastating pest of coffee, which shows clear evidence of HGT from bacteria. HhMAN1 encodes a mannanase, representing a class of glycosyl hydrolases that has not previously been reported in insects. Recombinant HhMAN1 protein hydrolyzes coffee berry galactomannan, the major storage polysaccharide in this species and the presumed food of H. hampei. HhMAN1 was found to be widespread in a broad biogeographic survey of H. hampei accessions, indicating that the HGT event occurred before radiation of the insect from West Africa to Asia and South America. However, the gene was not detected in the closely related species H. obscurus (the tropical nut borer or "false berry borer"), which does not colonize coffee beans. Thus, HGT of HhMAN1 from bacteria represents a likely adaptation to a specific ecological niche and may have been promoted by intensive agricultural practices.