Acute myocardial infarction (AMI) increasingly precipitates severe heart failure, with diagnoses now extending to progressively younger demographics. The focus of this study was to pinpoint critical genes linked to both AMI and anoikis, thereby unveiling potential novel biomarkers for AMI detection and intervention. Differential analysis was performed to identify significant differences in expression, and gene functionality was explored. Weighted gene coexpression network analysis (WGCNA) was used to construct gene coexpression networks. Immunoinfiltration analysis quantified immune cell abundance. Protein–protein interaction (PPI) analysis identified the proteins that interact with theanoikis. MCODE identified key functional modules. Drug enrichment analysis identified relevant compounds explored in the DsigDB. Through WGCNA, 13 key genes associated with anoikis and differentially expressed genes were identified. GO and KEGG pathway enrichment revealed the regulation of apoptotic signalling pathways and negative regulation of anoikis. PPI network analysis was also conducted, and 10 hub genes, such as IL1B, ZAP70, LCK, FASLG, CD4, LRP1, CDH2, MERTK, APOE and VTN were identified. IL1B were correlated with macrophages, mast cells, neutrophils and Tcells in MI, and the most common predicted medications were roxithromycin, NSC267099 and alsterpaullone. This study identified key genes associated with AMI and anoikis, highlighting their role in immune infiltration, diagnosis and medication prediction. These findings provide valuable insights into potential biomarkers and therapeutic targets for AMI.