Background and study aims Endoscopic ultrasound-guided through-the-needle biopsy (TTNB) of pancreatic cystic lesions (PCLs) is associated with a non-negligible risk for adverse events (AEs). We aimed to identify the hierarchic interaction among independent predictors for TTNB-related AEs and to generate a prognostic model using recursive partitioning analysis (RPA). Patients and methods Multicenter retrospective analysis of 506 patients with PCLs who underwent TTNB. RPA of predictors for AEs was performed and the model was validated by means of bootstrap resampling. Results Mean cysts size was 36.7 mm. Most common diagnoses were intraductal papillary mucinous neoplasm (IPMN, 45 %), serous cystadenoma (18.8 %), and mucinous cystadenoma (12.8 %). Fifty-eight (11.5 %) AEs were observed. At multivariate analysis, age (odds ratio [OR] 1.32, 1.09–2.14; p = 0.05), number of TTNB passes (OR from 2.17, 1.32–4.34 to OR 3.16, 2.03–6.34 with the increase of the number of passes), complete aspiration of the cyst (OR 0.56, 0.31–0.95; p = 0.02), and diagnosis of IPMN (OR 4.16, 2.27–7.69; p Conclusion TTNB should be selectively used in the evaluation of patients with IPMN. The present model could be applied during patient selection as to optimize the benefit/risk of TTNB.