PurposeObsessive‐compulsive disorder (OCD) is a complex psychiatric disorder. Genetic and broad environmental factors are common risk factors for OCD. The purpose of this study is to explore the molecular mechanism of OCD and to find new molecular targets for the diagnosis and management of OCD.MethodsAll data were downloaded from public dataset. Key modules and candidate key mRNAs were identified based on weighted gene co‐expression network analysis (WGCNA). The “limma” R package was used for differential expression analysis of mRNAs. Subsequently, functional enrichment analysis of differentially expressed mRNAs (DEmRNAs) was also carried out. In addition, a diagnostic model was constructed. Finally, the infiltration level of immune cells in OCD and its correlation with multicentric key DEmRNAs were analyzed.ResultsGreen and red modules were selected as the hub modules. A total of 447 mRNAs were considered candidate key mRNAs according to GS > 0.2 and MM > 0.3. A total of 26 DEmRNAs in the same direction were identified in the GSE60190 and GSE78104 datasets. A total of 26 DEmRNAs were intersected with candidate key mRNAs in WGCNA to obtain 10 intersection DEmRNAs (HSPB1, ITPK1, CBX7, PPP1R10, TAOK1, PISD, MKNK2, RWDD1, PPA1, and RELN). However, only four DEmRNAs (HSPB1, TAOK1, MKNK2, and PPA1) predicted related drugs. Subsequently, receiver operating characteristic analysis shows that the diagnostic model has high diagnostic value. Moreover, six multicentric key DEmRNAs (SNRPF, SNRNP70, PRPF8, NOP56, EPRS, and CCT2) were screened by UpSet package. Finally, six multicentric key DEmRNAs were found to be associated with immune cells.ConclusionThe key molecules obtained in this study lay a foundation for further research on the molecular mechanism of OCD.