It is inconclusive whether trimethylamine N-oxide (TMAO) and choline and related metabolites, namely trimethylamine (TMA), l-carnitine, betaine and dimethylglycine (DMG), are associated with non-alcoholic fatty liver disease (NAFLD). Our objective was to investigate these potential associations. Additionally, we sought to determine the mediating role of TMAO. In this 1:1 age- and sex-matched case–control study, a total of 150 pairs comprising NAFLD cases and healthy controls were identified. According to the fully adjusted model, after the highest tertile was compared with the lowest tertile, the plasma TMAO concentration (OR = 2·02 (95 % CI 1·04, 3·92); P trend = 0·003), l-carnitine concentration (OR = 1·79 (1·01, 3·17); P trend = 0·020) and DMG concentration (OR = 1·81 (1·00, 3·28); P trend = 0·014) were significantly positively associated with NAFLD incidence. However, a significantly negative association was found for plasma betaine (OR = 0. 50 (0·28, 0·88); P trend = 0·001). The restricted cubic splines model consistently indicated positive dose–response relationships between exposure to TMAO, l-carnitine, and DMG and NAFLD risk, with a negative association being observed for betaine. The corresponding AUC increased significantly from 0·685 (0·626, 0·745) in the traditional risk factor model to 0·769 (0·716, 0·822) when TMAO and its precursors were included (l-carnitine, betaine and choline) (P = 0·032). Mediation analyses revealed that 14·7 and 18·6 % of the excess NAFLD risk associated with l-carnitine and DMG, respectively, was mediated by TMAO (the P values for the mediating effects were 0·021 and 0·036, respectively). These results suggest that a higher concentration of TMAO is associated with increased NAFLD risk among Chinese adults and provide evidence of the possible mediating role of TMAO.