The foraging ecology of mammalian herbivores is strongly shaped by plant secondary compounds (PSCs) that defend plants against herbivory. Conventional wisdom holds that gut microbes facilitate the ingestion of toxic plants; however, this notion lacks empirical evidence. We investigated the gut microbiota of desert woodrats (Neotoma lepida), some populations of which specialise on highly toxic creosote bush (Larrea tridentata). Here, we demonstrate that gut microbes are crucial in allowing herbivores to consume toxic plants. Creosote toxins altered the population structure of the gut microbiome to facilitate an increase in abundance of genes that metabolise toxic compounds. In addition, woodrats were unable to consume creosote toxins after the microbiota was disrupted with antibiotics. Last, ingestion of toxins by naïve hosts was increased through microbial transplants from experienced donors. These results demonstrate that microbes can enhance the ability of hosts to consume PSCs and therefore expand the dietary niche breadth of mammalian herbivores.