Immune checkpoint inhibitors (ICIs) targeting the PD-1/PD-L1 axis induce sustained clinical responses in a sizable minority of cancer patients. We found that primary resistance to ICIs can be attributed to abnormal gut microbiome composition. Antibiotics inhibited the clinical benefit of ICIs in patients with advanced cancer. Fecal microbiota transplantation (FMT) from cancer patients who responded to ICIs into germ-free or antibiotic-treated mice ameliorated the antitumor effects of PD-1 blockade, whereas FMT from nonresponding patients failed to do so. Metagenomics of patient stool samples at diagnosis revealed correlations between clinical responses to ICIs and the relative abundance of Akkermansia muciniphila. Oral supplementation with A. muciniphila after FMT with nonresponder feces restored the efficacy of PD-1 blockade in an interleukin-12–dependent manner by increasing the recruitment of CCR9+CXCR3+CD4+ T lymphocytes into mouse tumor beds.