Agaric is a dual‐purpose fungus for medicine and food, which is considered a healthcare product. However, in cultivation and production, agaric is contaminated by a variety of molds, resulting in a decline in quality and yield. Fusarium, as one of the poisonous filamentous fungi, seriously threatens the healthy development of the agaric industry and even affects human health. Therefore, it is necessary to establish timely and accurate identification and rapid detection of pathogens and crops. In this study, the visible near infrared hyperspectral imaging was used to obtain the image and spectral information, and the best classification model was selected and established to quickly distinguish Fusarium oxysporum from Fusarium verticillioides, which was also successfully applied for the preliminary identification of agaric infection. This approach could provide a nondestructive manner for rapid identification and detection of pathogenic fungi contamination in agaric.