Postoperative atrial fibrillation (POAF) complicates 20-40% of cardiac surgical procedures and 10-20% of non-cardiac thoracic operations. Typical features include onset at 2-4 days postoperatively, episodes that are often fleeting and a self-limited time course. Associated adverse consequences of POAF include haemodynamic instability, increased risk of stroke, lengthened hospital and intensive care unit stays and greater costs. Underlying mechanisms are incompletely defined but include intraoperative and postoperative phenomena, such as inflammation, sympathetic activation and cardiac ischaemia, that combine to trigger atrial fibrillation, often in the presence of pre-existing factors, making the atria vulnerable to atrial fibrillation induction and maintenance. A better understanding of the underlying mechanisms might enable the identification of new therapeutic targets. POAF can be prevented by targeting autonomic alterations and inflammation. β-Blocker prophylaxis is the best-established preventive therapy and should be started or continued before cardiac surgery, unless contraindicated. When POAF occurs, rate control usually suffices, and routine rhythm control is unnecessary; rhythm control should be reserved for patients who develop haemodynamic instability or show other indications that rate control alone will be insufficient. In this Review, we summarize the epidemiological and clinical features of POAF, the available pathophysiological evidence from clinical and experimental investigations, the results of prophylactic and therapeutic approaches and the consensus recommendations of various national and international societies.