The relationship between diet-related inflammation during pregnancy and congenital heart defects (CHD) is unclear. This study attempted to investigate the association between the dietary inflammation index (DII) during pregnancy, reflecting the overall inflammatory potential of the maternal diet, and CHD in Northwest China. A case-control study with 474 cases and 948 controls was performed in Xi’an City, China. Eligible women awaiting delivery were recruited, and their dietary and other information during pregnancy was collected. Logistic regression models were applied to estimate the risk of CHD in association with DII. The maternal DII ranged from −1.36 to 5.73 in cases, and 0.43 to 5.63 in controls. Pregnant women with per 1 higher DII score were at 31% higher risk of fetal CHD (OR = 1.31, 95%CI = 1.14–1.51), and the adjusted OR (95%CI) comparing the pro-inflammatory diet group with the anti-inflammatory diet group was 2.04 (1.42–2.92). The inverse association of maternal DII score with CHD risk was consistent across various subgroups of maternal characteristics. Maternal DII in pregnancy had good predictive value for CHD in offspring, with the areas under the receiver operating characteristic curve higher than 0.7. These findings suggested that avoiding a pro-inflammatory diet in pregnancy should be emphasized in the prevention of CHD.