In this study, we screened potential natural compounds for the treatment of myocardial infarction (MI) and explored the underlying mechanisms. We built three machine learning models to screen the potential compounds. qPCR, flow cytometry, immunohistochemistry, and immunofluorescence analyses were applied to analyze the pharmacological effects of the compounds on macrophages/monocytes in vivo and in vitro. Arctigenin (AG) was selected as a candidate, and echocardiography, Masson’s trichrome staining, and TUNEL staining were utilized to detect the effect of AG on MI in vivo. Transcriptome analysis and subsequent bioinformatics analyses were performed to predict the target of the selected compound. Western blot and luciferase reporter assays were used to confirm the target and mechanism of AG. The reversibility of the effects of AG were verified through overexpression of NFAT5. The results showed that AG can improve cardiac injury after MI by reducing infarct size, improving heart function, and inhibiting cardiac death. In addition, AG suppresses inflammatory macrophages/monocytes and proinflammatory cytokines in vivo and in vitro. Transcriptomic and biological experiments revealed that AG modulates macrophage polarization via the NFAT5-induced signaling pathway. Therefore, our data suggest that AG can improve MI by inhibiting the inflammatory phenotype of macrophages/monocytes through targeting of NFAT5.