Autism spectrum disorder (ASD) is a heterogeneous group of complex neurodevelopmental disorders with evidence of genetic predisposition. Intestinal disturbances are reported in ASD patients and compositional changes in gut microbiota are described. However, the role of microbiota in brain disorders is poorly documented. Here, we used a murine model of ASD to investigate the relation between gut microbiota and autism-like behaviour. Using next generation sequencing technology, microbiota composition was investigated in mice in utero exposed to valproic acid (VPA). Moreover, levels of short chain fatty acids (SCFA) and lactic acid in caecal content were determined. Our data demonstrate a transgenerational impact of in utero VPA exposure on gut microbiota in the offspring. Prenatal VPA exposure affected operational taxonomic units (OTUs) assigned to genera within the main phyla of Bacteroidetes and Firmicutes and the order of Desulfovibrionales, corroborating human ASD studies. In addition, OTUs assigned to genera of Alistipes, Enterorhabdus, Mollicutes and Erysipelotrichalis were especially associated with male VPA-exposed offspring. The microbial differences of VPA in utero-exposed males deviated from those observed in females and was (i) positively associated with increased levels of caecal butyrate as well as ileal neutrophil infiltration and (ii) inversely associated with intestinal levels of serotonin and social behaviour scores. These findings show that autism-like behaviour and its intestinal phenotype is associated with altered microbial colonization and activity in a murine model for ASD, with preponderance in male offspring. These results open new avenues in the scientific trajectory of managing neurodevelopmental disorders by gut microbiome modulation.