Acute myocardial infarction (AMI) is one of the leading causes of death globally, with a mortality rate of over 20%. However, the diagnostic biomarkers frequently used in current clinical practice have limitations in both sensitivity and specificity, likely resulting in delayed diagnosis. This study aimed to identify potential diagnostic biomarkers for AMI and explored the possible mechanisms involved. Datasets were retrieved from the Gene Expression Omnibus. First, we identified differentially expressed genes (DEGs) and preserved modules, from which we identified candidate genes by LASSO (least absolute shrinkage and selection operator) regression and the SVM-RFE (support vector machine-recursive feature elimination) algorithm. Subsequently, we used ROC (receiver operating characteristic) analysis to evaluate the diagnostic accuracy of the candidate genes. Thereafter, functional enrichment analysis and an analysis of immune infiltration were implemented. Finally, we assessed the association between biomarkers and biological processes, infiltrated cells, clinical traits, tissues and time points. We identified nine preserved modules containing 1,016 DEGs and managed to construct a diagnostic model with high accuracy (GSE48060: AUC = 0.923; GSE66360: AUC = 0.973) incorporating two genes named S100A9 and SOCS3. Functional analysis revealed the pivotal role of inflammation; immune infiltration analysis indicated that eight cell types (monocytes, epithelial cells, neutrophils, CD8 + T cells, Th2 cells, NK cells, NKT cells and platelets) were likely involved in AMI. Furthermore, we observed that S100A9 and SOCS3 were correlated with inflammation, variably infiltrated cells, clinical traits of patients, sampling tissues and sampling time points. In conclusion, we suggested S100A9 and SOCS3 as diagnostic biomarkers of AMI and discovered their association with inflammation, infiltrated immune cells and other factors.