β-cell dysfunction, manifested as impaired glucose-stimulated insulin secretion (GSIS), and β-cell loss, presented as dedifferentiation, inhibited transcriptional identity and death, are the hallmarks of type 2 diabetes. Trimethylamine N-oxide (TMAO), a gut microbiota metabolite, has been shown to play a role in cardiovascular disease. Here, we found that plasma TMAO levels are elevated in both diabetic mice and subjects and that TMAO at a similar concentration of diabetes could directly decrease β-cell GSIS in both MIN6 cells and primary islets from mice or humans. Elevation of TMAO levels through choline diet feeding impairs GSIS, β-cell proportion, and glucose tolerance. Inhibition of TMAO production through either genetic knockdown or antisense oligomers of Fmo3, the TMAO-producing enzyme, improves β-cell GSIS, β-cell proportion, and glucose tolerance in both db/db and choline diet-fed mice. Mechanistically, TMAO inhibits calcium transients through Serca2. Additionally, long-term TMAO exposure promotes β-cell ER stress, dedifferentiation, and apoptosis and inhibits β-cell transcriptional identity. These observations elucidate a novel role for TMAO in β-cell dysfunction and maintenance, and inhibition of TMAO could be a new approach for the treatment of type 2 diabetes.