Hypersensitivity pneumonitis (HP) is an immunologically mediated form of lung disease resulting from inhalational exposure to any of a large variety of antigens. A subgroup of patients with HP develops pulmonary fibrosis (fibrotic HP; FHP), a significant cause of morbidity and mortality. This study will evaluate the safety and efficacy of the antifibrotic pirfenidone in treating FHP.This single-centre, randomised, double-blind, placebo-controlled trial is enrolling adults with FHP (ClinicalTrials.gov: NCT02958917). Study participants must have fibrotic abnormalities involving ≥5% of the lung parenchyma on high-resolution computed tomography scan, forced vital capacity (FVC) ≥40% and diffusing capacity of the lung for carbon monoxide ≥30% of predicted values. Study participants will be randomised in a 2:1 ratio to receive pirfenidone 2403 mg·day−1 or placebo. The primary efficacy end-point is the mean change in FVC % predicted from baseline to week 52. A number of secondary end-points have been chosen to evaluate the safety and efficacy in different domains.