Abstractβ-Cell dysfunction and β-cell loss are hallmarks of type 2 diabetes (T2D). Here, we found that trimethylamine N-oxide (TMAO) at a similar concentration to that found in diabetes could directly decrease glucose-stimulated insulin secretion (GSIS) in MIN6 cells and primary islets from mice or humans. Elevation of TMAO levels impairs GSIS, β-cell proportion, and glucose tolerance in male C57BL/6 J mice. TMAO inhibits calcium transients through NLRP3 inflammasome-related cytokines and induced Serca2 loss, and a Serca2 agonist reversed the effect of TMAO on β-cell function in vitro and in vivo. Additionally, long-term TMAO exposure promotes β-cell ER stress, dedifferentiation, and apoptosis and inhibits β-cell transcriptional identity. Inhibition of TMAO production improves β-cell GSIS, β-cell proportion, and glucose tolerance in both male db/db and choline diet-fed mice. These observations identify a role for TMAO in β-cell dysfunction and maintenance, and inhibition of TMAO could be an approach for the treatment of T2D.