Background: There is bidirectional communication between the gut microbiota and the brain. Empirical evidence has demonstrated sex differences in both the gut microbiome and the brain. However, the effects of sex on the gut microbiota-brain associations have yet to be determined. Methods: 157 healthy young adults underwent brain structural, perfusion, functional and diffusion MRIs to measure gray matter volume (GMV), cerebral blood flow (CBF), functional connectivity strength (FCS) and white matter integrity, respectively. Fecal samples were collected and 16S rRNA gene amplicon sequencing was utilized to assess gut microbial diversity. Correlation analyses were conducted to test for sex-dependent associations between microbial diversity and brain imaging parameters, and mediation analysis was performed to further characterize the gut microbiota-brain-cognition relationship. Results: We found that higher gut microbial diversity was associated with higher GMV in the right cerebellum Ⅵ, higher CBF in the bilateral calcarine sulcus yet lower CBF in the left superior frontal gyrus, higher FCS in the bilateral paracentral lobule, and lower diffusivity in widespread white matter regions in males. However, these associations were absent in females. Of more importance, these neuroimaging biomarkers significantly mediated the association between gut microbial diversity and behavioral inhibition in males. Conclusions: These findings highlight sex as a potential influential factor underlying the gut microbiota-brain-cognition relationship, and expose the gut microbiota as a biomarker-driven and sex-sensitive intervention target for mental disorders with abnormal behavioral inhibition.