Cancer patients often experience impairments in cognitive function. However, the evidence for tumor-mediated neurological impairment and detailed mechanisms are still lacking. Gut microbiota has been demonstrated to be involved in the immune system homeostasis and brain functions. Here we find that hepatocellular carcinoma (HCC) growth alters the gut microbiota and impedes the cognitive functions. The synaptic tagging and capture (STC), an associative cellular mechanism for the formation of associative memory, is impaired in the tumor-bearing mice. STC expression is rescued after microbiota sterilization. Transplantation of microbiota from HCC tumor-bearing mice induces similar STC impairment in wide type mice. Mechanistic study reveals that HCC growth significantly elevates the serum and hippocampus IL-1β levels. IL-1β depletion in the HCC tumor-bearing mice restores the STC. Taken together, these results demonstrate that gut microbiota plays a crucial role in mediating the tumor-induced impairment of the cognitive function via upregulating IL-1β production.