The study aimed to investigate the association of adults adhering to Dietary Approaches to Stop Hypertension (DASH) and Mediterranean diet (MeD) with nonalcoholic fatty liver disease (NAFLD) using structural equation modeling (SEM) in Iran. In this population-based cross-sectional study, 3,220 adults (44.65% female) aged ≥18 years were selected from the Amol Cohort Study (AmolCS). The dietary intakes were assessed by a validated 168-item semi-quantitative food-frequency questionnaire (FFQ). Residual method energy adjustment of MeD and DASH scores were calculated. Demographic characteristics and anthropometric and laboratory measurements were collected. NAFLD was diagnosed by an expert radiologist via ultrasound sonography. Based on the primary hypothesis, DASH, MeD, and NAFLD were fitted into models. Metabolic syndrome (MeS) as a potential risk factor directly affected NAFLD risk in all these models. In both genders, the higher adherence to DASH negatively affected NAFLD risk indirectly through the two following paths. (1) Dietary acid load (DAL) and metabolic syndrome (2) DAL and hemoglobin A1c (HbA1c). In addition, the higher DAL positively affected NAFLD risk among male participants indirectly via increasing HbA1c level and MeS (from DAL to HbA1c: β = 0.07, P < 0.001; from HbA1c to MeS: β = 0.10, P < 0.001). Similarly, in both genders, the relationship between MeD and NAFLD was mediated through (1) DAL, HbA1c, and MeS and (2) DAL and MeS. Further, among male participants, the MeD and NAFLD risk were also associated via the mediators of HbA1c and MeS. In female participants, the higher MeD score was directly associated with a reduction of NAFLD risk (β = −0.07, P = 0.008). The present study found three important mediators, including DAL, HbA1c, and MeS, in the association of DASH and MeD scores with NAFLD risk. Preventive and therapeutic interventions should target the mediators, including DAL, HbA1c, MeS, and its components, to reduce NAFLD incidence in the general population.