The effect of T lymphocytes on atrial fibrillation (AF) is still unclear. We aimed to assess the associations between the T lymphocyte subgroup distribution and incident AF and AF prognosis. Consecutive patients were enrolled from June 2020 to October 2021. Their T-cell subgroups, including CD3, CD4, and CD8 T cells, and the CD4/CD8 ratio (CDR) were measured. We assessed the relationships between the CDR and composite endpoints, including hospitalization due to heart failure, stroke or systemic embolism, and cardiovascular mortality rates. A total of 45905 patients, among whom 818 had AF, were enrolled. The proportions of the T lymphocyte subgroups CD3 (OR 0.9995; 95% CI 0.9993-0.9997, P < 0.001), CD4 (OR 0.9995; 95% CI 0.9991-0.9998, P = 0.004), and CD8 (OR 0.9988; 95% CI 0.9984-0.9992, P < 0.001) and the CDR (OR 1.2714; 95% CI 1.1355-1.4165, P < 0.001) were correlated with AF incidence. The CDR was associated with AF incidence (OR 1.1998; 95% CI 1.0746-1.3336, P<0.001) after adjustment. High CDR was associated with a higher rate of hospitalization due to heart failure (HR 3.45; 95% CI 1.71-6.96, P < 0.001), stroke or systemic embolism (HR 2.54; 95% CI 1.32-4.91, P = 0.005), and cardiovascular mortality (HR 2.25; 95% CI 1.05-4.84, P = 0.038). There was no significant difference in all-cause mortality between CDR strata (HR 1.61; 95% CI 0.90-2.87, P = 0.111). Elevated CDR was positively associated with the incidence and prognosis of AF. This finding may help improve the prevention and treatment of AF.