Peanut seeds are susceptible to Aspergillus flavus infection, which has a severe impact on the peanut industry and human health. However, the molecular mechanism underlying this defense remains poorly understood. The aim of this study was to analyze the changes in differentially expressed genes (DEGs) and differential metabolites during A. flavus infection between Zhonghua 6 and Yuanza 9102 by transcriptomic and metabolomic analysis. A total of 5768 DEGs were detected in the transcriptomic study. Further functional analysis showed that some DEGs were significantly enriched in pectinase catabolism, hydrogen peroxide decomposition and cell wall tissues of resistant varieties at the early stage of infection, while these genes were differentially enriched in the middle and late stages of infection in the nonresponsive variety Yuanza 9102. Some DEGs, such as those encoding transcription factors, disease course-related proteins, peroxidase (POD), chitinase and phenylalanine ammonialyase (PAL), were highly expressed in the infection stage. Metabolomic analysis yielded 349 differential metabolites. Resveratrol, cinnamic acid, coumaric acid, ferulic acid in phenylalanine metabolism and 13S-HPODE in the linolenic acid metabolism pathway play major and active roles in peanut resistance to A. flavus. Combined analysis of the differential metabolites and DEGs showed that they were mainly enriched in phenylpropane metabolism and the linolenic acid metabolism pathway. Transcriptomic and metabolomic analyses further confirmed that peanuts infected with A. flavus activates various defense mechanisms, and the response to A. flavus is more rapid in resistant materials. These results can be used to further elucidate the molecular mechanism of peanut resistance to A. flavus infection and provide directions for early detection of infection and for breeding peanut varieties resistant to aflatoxin contamination.