Abstract Background Communication between the gut microbiota and the brain is primarily mediated via soluble microbe-derived metabolites, but the details of this pathway remain poorly defined. Methylamines produced by microbial metabolism of dietary choline and l-carnitine have received attention due to their proposed association with vascular disease, but their effects upon the cerebrovascular circulation have hitherto not been studied. Results Here, we use an integrated in vitro/in vivo approach to show that physiologically relevant concentrations of the dietary methylamine trimethylamine N-oxide (TMAO) enhanced blood-brain barrier (BBB) integrity and protected it from inflammatory insult, acting through the tight junction regulator annexin A1. In contrast, the TMAO precursor trimethylamine (TMA) impaired BBB function and disrupted tight junction integrity. Moreover, we show that long-term exposure to TMAO protects murine cognitive function from inflammatory challenge, acting to limit astrocyte and microglial reactivity in a brain region-specific manner. Conclusion Our findings demonstrate the mechanisms through which microbiome-associated methylamines directly interact with the mammalian BBB, with consequences for cerebrovascular and cognitive function. Video abstract