The objective of the present study is to assess the bidirectional association between heart failure (HF) and atrial fibrillation (AF) using real-world data. From an electronic health recording with a population of 3799885 adult subjects, those with prevalent or incident HF were selected and followed throughout a study period of 5years. Prevalence and incidence of AF, and their impact in the risk for acute HF hospitalization, worsening renal function, ischaemic and haemorrhagic stroke, and all-cause mortality were identified. We analysed all incident and prevalent patients with HF and AF, 128086 patients (S1), and subsequently analysed a subset of patients with incident HF and AF, 57354 patients (S2). We analysed all incident and prevalent patients with HF and AF, 128086 patients (S1), and subsequently a subset of patients with incident HF and AF, 57354 patients (S2). The prevalence of AF was 59906 (46.7%) of the HF patients, while incidence in the S2 was 231/1000 patients/year. In both cohorts, S1 and S2, AF significantly increases the risk of acute heart failure hospitalization [incidence 79.1/1000 and 97.5/1000 patients/year; HR 1.53 (1.48-1.59 95% CI) and HR 1.32 (1.24-1.41 95% CI), respectively], risk of decreased renal function (eGFR reduced by >20%) [66.2/1000 and 94.0/1000 patients/year; HR 1.13 (1.09-1.18 95% CI) and HR 1.22 (1.14-1.31 95% CI), respectively] and all-cause mortality [203/1000 and 294/1000 patients/year; HR 1.62 (1.58-1.65 95% CI) and HR 1.65 (1.59-1.70 95% CI), respectively]. The number of episodes of hospitalization for acute heart failure was also significantly higher in the AF patients (27623 vs. 10036, P<0.001). However, the risk for ischaemic stroke was reduced in the AF subjects [HR 0.66 (0.63-0.74 95% CI)], probably due to the anticoagulant treatment. AF is associated with an increment in the risk of episodes of acute heart failure as well as decline of renal function and increment of all-cause mortality.