Recent evidence points to the gut microbiota as a regulator of brain and behavior, although it remains to be determined if gut bacteria play a role in chronic pain. The endocannabinoid system is implicated in inflammation and chronic pain processing at both the gut and central nervous system (CNS) levels. In the present study, we used low Vitamin D dietary intake in mice and evaluated possible changes in gut microbiota, pain processing and endocannabinoid system signaling. Vitamin D deficiency induced a lower microbial diversity characterized by an increase in Firmicutes and a decrease in Verrucomicrobia and Bacteroidetes. Concurrently, vitamin D deficient mice showed tactile allodynia associated with neuronal hyperexcitability and alterations of endocannabinoid system members (endogenous mediators and their receptors) at the spinal cord level. Changes in endocannabinoid (anandamide and 2-arachidonoylglycerol) levels were also observed in the duodenum and colon. Remarkably, the anti-inflammatory anandamide congener, palmitoylethanolamide, counteracted both the pain behaviour and spinal biochemical changes in vitamin D deficient mice, whilst increasing the levels of Akkermansia, Eubacterium and Enterobacteriaceae, as compared with vehicle-treated mice. Finally, induction of spared nerve injury in normal or vitamin D deficient mice was not accompanied by changes in gut microbiota composition. Our data suggest the existence of a link between Vitamin D deficiency – with related changes in gut bacterial composition – and altered nociception, possibly via molecular mechanisms involving the endocannabinoid and related mediator signaling systems.