Although dietary patterns, specific foods, and their constituents have been linked to cancer risk, the role of dietary patterns and specific food groups in liver cancer risk has not been investigated. In the Shanghai Women's Health Study (SWHS) and Shanghai Men's Health Study (SMHS), two cohort studies of 132 837 Chinese women and men, we evaluated the relationship between dietary patterns, food groups, and liver cancer risk. Through in-person interviews, dietary information intake over the preceding year was collected by using a validated food-frequency questionnaire. Cox regression model was used to estimate hazard ratios and 95% confidence intervals with adjustment for potential confounders. During an average follow-up of 10.9 (SWHS) or 5.5 (SMHS) years, 267 incident liver cancer cases were identified after the first 2 years of study enrolment. Three dietary patterns were derived by factor analysis. A vegetable-based dietary pattern was inversely associated with liver cancer; hazard ratios (95% confidence intervals) for the lowest to highest quartiles were: 1.00; 0.98 (0.71–1.35); 0.93 (0.67–1.29); and 0.58 (0.40–0.84); Ptrend = 0.01. The association was stronger among participants with a history of chronic liver disease. Further analyses showed high intakes of celery, mushrooms, allium vegetables, composite vegetables (including asparagus lettuce and garland chrysanthemum), legumes and legume products were associated with reduced liver cancer risk (all Ptrend < 0.05). Fruit- and meat-based dietary patterns were not associated with liver cancer risk. Our study suggests that a vegetable-based dietary pattern is associated with reduced liver cancer risk.