Background: Early recognition and management of postoperative complications, before they become clinically relevant, can improve postoperative outcomes for patients, especially for high-risk procedures such as pancreatic resection. Methods: We did an open-label, nationwide, stepped-wedge cluster-randomised trial that included all patients having pancreatic resection during a 22-month period in the Netherlands. In this trial design, all 17 centres that did pancreatic surgery were randomly allocated for the timing of the crossover from usual care (the control group) to treatment given in accordance with a multimodal, multidisciplinary algorithm for the early recognition and minimally invasive management of postoperative complications (the intervention group). Randomisation was done by an independent statistician using a computer-generated scheme, stratified to ensure that low–medium-volume centres alternated with high-volume centres. Patients and investigators were not masked to treatment. A smartphone app was designed that incorporated the algorithm and included the daily evaluation of clinical and biochemical markers. The algorithm determined when to do abdominal CT, radiological drainage, start antibiotic treatment, and remove abdominal drains. After crossover, clinicians were trained in how to use the algorithm during a 4-week wash-in period; analyses comparing outcomes between the control group and the intervention group included all patients other than those having pancreatic resection during this wash-in period. The primary outcome was a composite of bleeding that required invasive intervention, organ failure, and 90-day mortality, and was assessed by a masked adjudication committee. This trial was registered in the Netherlands Trial Register, NL6671. Findings: From Jan 8, 2018, to Nov 9, 2019, all 1805 patients who had pancreatic resection in the Netherlands were eligible for and included in this study. 57 patients who underwent resection during the wash-in phase were excluded from the primary analysis. 1748 patients (885 receiving usual care and 863 receiving algorithm-centred care) were included. The primary outcome occurred in fewer patients in the algorithm-centred care group than in the usual care group (73 [8%] of 863 patients vs 124 [14%] of 885 patients; adjusted risk ratio [RR] 0·48, 95% CI 0·38–0·61; p<0·0001). Among patients treated according to the algorithm, compared with patients who received usual care there was a decrease in bleeding that required intervention (47 [5%] patients vs 51 [6%] patients; RR 0·65, 0·42–0·99; p=0·046), organ failure (39 [5%] patients vs 92 [10%] patients; 0·35, 0·20–0·60; p=0·0001), and 90-day mortality (23 [3%] patients vs 44 [5%] patients; 0·42, 0·19–0·92; p=0·029). Interpretation: The algorithm for the early recognition and minimally invasive management of complications after pancreatic resection considerably improved clinical outcomes compared with usual care. This difference included an approximate 50% reduction in mortality at 90 days. Funding: The Dutch Cancer Society and UMC Utrecht.