BackgroundSex differences and causality of the association between heart rate variability (HRV) and atrial fibrillation (AF) in the general population remain unclear.Methods12,334 participants free of AF from the population-based Rotterdam Study were included. Measures of HRV including the standard deviation of normal RR intervals (SDNN), SDNN corrected for heart rate (SDNNc), RR interval differences (RMSSD), RMSSD corrected for heart rate (RMSSDc), and heart rate were assessed at baseline and follow-up examinations. Joint models, adjusted for cardiovascular risk factors, were used to determine the association between longitudinal measures of HRV with new-onset AF. Genetic variants for HRV were used as instrumental variables in a Mendelian randomization (MR) analysis using genome-wide association studies (GWAS) summary-level data.ResultsDuring a median follow-up of 9.4 years, 1302 incident AF cases occurred among 12,334 participants (mean age 64.8 years, 58.3% women). In joint models, higher SDNN (fully-adjusted hazard ratio (HR), 95% confidence interval (CI) 1.24, 1.04–1.47,p= 0.0213), and higher RMSSD (fully-adjusted HR, 95% CI 1.33, 1.13–1.54,p= 0.0010) were significantly associated with new-onset AF. Sex-stratified analyses showed that the associations were mostly prominent among women. In MR analyses, a genetically determined increase in SDNN (odds ratio (OR), 95% CI 1.60, 1.27–2.02,p= 8.36 × 10–05), and RMSSD (OR, 95% CI 1.56, 1.31–1.86,p= 6.32 × 10–07) were significantly associated with an increased odds of AF.ConclusionLongitudinal measures of uncorrected HRV were significantly associated with new-onset AF, especially among women. MR analyses supported the causal relationship between uncorrected measures of HRV with AF. Our findings indicate that measures to modulate HRV might prevent AF in the general population, in particular in women.Graphical abstractAF; atrial fibrillation,GWAS; genome-wide association study,IVW; inverse variance weighted,MR; Mendelian randomization,MR-PRESSO; MR-egger and mendelian randomization pleiotropy residual sum and outlier,RMSSD; root mean square of successive RR interval differences,RMSSDc; root mean square of successive RR interval differences corrected for heart rate,SDNN; standard deviation of normal to normal RR intervals,SDNNc; standard deviation of normal to normal RR intervals corrected for heart rate,WME; weighted median estimator.aRotterdam Studyn=12,334bHRV GWASn=53,174cAF GWASn=1,030,836Supplementary InformationThe online version contains supplementary material available at 10.1007/s00392-022-02072-5.