Patients with idiopathic pulmonary fibrosis (IPF) often develop postoperative severe respiratory complications such as acute exacerbation. Pirfenidone, an oral anti-fibrotic drug, may reduce the incidence of such complications. However, the preventive effect of pirfenidone on postoperative severe respiratory complications remains unclear. We identified patients with IPF who underwent surgery with general anaesthesia from July 2010 to March 2018 using the Diagnosis Procedure Combination database. We compared the occurrence of postoperative severe respiratory complications (receiving mechanical ventilation under endotracheal intubation and/or intravenous infusion of a high-dose corticosteroid and in-hospital death within 30 days after surgery) between patients who did and did not receive preoperative treatment with pirfenidone. Pearson's chi-square test and logistic regression analysis fitted with a generalized estimating equation were conducted in 1:4 propensity score-matched patients. Among 631 patients identified, 19% were treated with pirfenidone before surgery. The 30-day mortality rate was 3.1% and 1.7% in the control patients (n= 510) and pirfenidone-treated patients (n= 121), respectively. In the propensity score-matched population, preoperative treatment with pirfenidone was significantly associated with a lower proportion of postoperative severe respiratory complications (OR: 0.24; 95% CI: 0.07-0.76; p= 0.015). In this Japanese nationwide cohort, preoperative treatment with pirfenidone was significantly associated with a lower risk of postoperative severe respiratory complications in patients with IPF. Preoperative pirfenidone may thus be useful in preventing postoperative severe respiratory complications in patients with IPF who are planning to undergo surgery with general anaesthesia.