Atrial fibrillation (AF) is a common tachyarrhythmia whose pathogenesis remains elusive. In the present study, we aimed to investigate the pathological mechanism of mitophagy and immunoinfiltration in AF. First, we identified differentially expressed mitophagy-related genes (DEMRGs) based on the GSE79768 and GSE115574 datasets, subjecting them to functional enrichment analysis. STRING, TRRUST, miRNet, miRwalk, and Cytoscape were used to explore the potential regulatory roles of downstream signaling pathways. Subsequently, the random forest method was used to construct the AF risk model, and the DEMRGs most correlated with AF risk were determined by combining the Gini index. ssGSEA algorithm, NMF algorithm, and unsupervised clustering were used to subdivide AF molecular types. We then studied the characteristics of mitophagy- and immune infiltration-related genes in AF. Ultimately, we detected the expression of key genes in canine atrial tissues and HL-1 cells by immunofluorescence and Western blot. Mitophagy and immune infiltration were significantly enriched and activated in AF samples. Thirty-seven DEMRGs were screened, of which MAPK1, VDAC1, MAPK14, and MTERF3 were most associated with AF risk. The risk model based on these could identify patients at a high risk of AF. The infiltration of immunocells such as mast cells and neutrophils was significantly different among AF types. Finally, expression verification indicated that the expression trend of four key genes in canine atrial muscle tissue and HL-1 cells was consistent. We found that mitophagy may participate in AF progression through immune activation. In addition, the AF risk prediction model composed of VDAC1, MAPK1, MAPK14, and MTERF3 has a good AF prediction performance, which provides new ideas for the study of AF pathogenesis and potential therapeutic targets.