Low circulating levels of total 25-hydroxyvitamin D (25(OH)D) have been associated with an increased risk of adverse effects after cardiac surgery. The metabolites, 25(OH)D2 and 25(OH)D3, provide a good index of vitamin D status. In this study, we examined the association between preoperative plasma levels of total 25(OH)D, 25(OH)D2 and 25(OH)D3 and the risk of postoperative atrial fibrillation (POAF) following open heart surgery. The levels of plasma 25(OH)D2 and 25(OH)D3 in 118 patients, who underwent coronary artery bypass grafting and/or valvular surgery, were measured immediately prior to surgery and on postoperative day 3 by liquid chromatography–tandem mass spectrometry. Patients who developed POAF had higher median plasma levels of 25(OH)D2 than those who remained in sinus rhythm (SR) (P = 0·003), but no significant difference was noted in levels of 25(OH)D3 or total 25(OH)D between the two groups (P > 0·05). By univariate analysis, patients with total 25(OH)D and 25(OH)D2 levels above the median had higher frequency of POAF (P < 0·05) and the incidence of POAF increased significantly with each higher quartile of preoperative plasma levels of 25(OH)D2 (P = 0·001), an association that was independent of confounding factors. In both the SR and POAF groups, the median plasma levels of 25(OH)D2, 25(OH)D3 and total 25(OH)D were lower (P < 0·05) on the third postoperative day compared with preoperatively. Our findings demonstrate that higher plasma levels of 25(OH)D2 are associated with increased risk of POAF, while this is not the case for 25(OH)D3 or total 25(OH)D. The reason for these discrepant results is not clear but warrants further study.