Generalized anxiety disorder (GAD) and obsessive-compulsive disorder (OCD) had high comorbidity and affected more than 44 million people around the world leading to a huge burden on health and economy. Here, we conducted an epigenome-wide DNA methylation study employing 93 patients with GAD, 65 patients with OCD, and 302 health controls, to explore epigenetic alterations associated with the onset and differences of GAD and OCD. We identified multiple differentially methylated positions (DMPs) and regions (DMRs): three DMP genes included RIOK3 (cg21515243, p = 8.00 × 10−10), DNASE2 (cg09379601, p = 1.10 × 10−9), and PSMB4 (cg01334186, p = 3.70 × 10−7) and two DMR genes USP6NL (p = 4.50 × 10−4) and CPLX1 (p = 6.95 × 10−4) were associated with the onset of GAD and OCD; three DMPs genes included LDLRAP1 (cg21400344, p = 4.40 × 10−12), ACIN1 (cg23712970, p = 2.98×10−11), and SCRT1 (cg25472897, p = 5.60 × 10−11) and three DMR genes WDR19 (p = 3.39 × 10−3), SYCP1 (p = 6.41 × 10−3), and FAM172A (p = 5.74 × 10−3) were associated with the differences between GAD and OCD. Investigation of epigenetic age and chronological age revealed a different epigenetic development trajectory of GAD and OCD. Conclusively, our findings which yielded robust models may aid in distinguishing patients from healthy controls (AUC = 0.90–0.99) or classifying patients with GAD and OCD (AUC = 0.89–0.99), and may power the precision medicine for them.