The composition of the gut microbiome can control innate and adaptive immunity and has emerged as a key regulator of tumor growth, especially in the context of immune checkpoint blockade (ICB) therapy. However, the underlying mechanisms for how the microbiome affects tumor growth remain unclear. Pancreatic ductal adenocarcinoma (PDAC) tends to be refractory to therapy, including ICB. Using a nontargeted, liquid chromatography-tandem mass spectrometry-based metabolomic screen, we identified the gut microbe-derived metabolite trimethylamine N-oxide (TMAO), which enhanced antitumor immunity to PDAC. Delivery of TMAO intraperitoneally or via a dietary choline supplement to orthotopic PDAC-bearing mice reduced tumor growth, associated with an immunostimulatory tumor-associated macrophage (TAM) phenotype, and activated effector T cell response in the tumor microenvironment. Mechanistically, TMAO potentiated the type I interferon (IFN) pathway and conferred antitumor effects in a type I IFN-dependent manner. Delivering TMAO-primed macrophages intravenously produced similar antitumor effects. Combining TMAO with ICB (anti-PD1 and/or anti-Tim3) in a mouse model of PDAC significantly reduced tumor burden and improved survival beyond TMAO or ICB alone. Last, the levels of bacteria containing CutC (an enzyme that generates trimethylamine, the TMAO precursor) correlated with long-term survival in patients with PDAC and improved response to anti-PD1 in patients with melanoma. Together, our study identifies the gut microbial metabolite TMAO as a driver of antitumor immunity and lays the groundwork for potential therapeutic strategies targeting TMAO.