Pancreatic cancers are usually detected at an advanced stage and have poor prognosis. About one fifth of these arise from pancreatic cystic lesions. Yet not all lesions are precancerous, and imaging tools lack adequate accuracy for distinguishing precancerous from benign cysts. Therefore, decisions on surgical resection usually rely on endoscopic ultrasound-guided fine needle aspiration (EUS-FNA). Unfortunately, cyst fluid often contains few cells, and fluid chemical analysis lacks accuracy, resulting in dire consequences, including unnecessary pancreatic surgery for benign cysts and the development of cancer. Here, we report an optical spectroscopic technique, based on a spatial gating fibre-optic probe, that predicts the malignant potential of pancreatic cystic lesions during routine diagnostic EUS-FNA procedures. In a double-blind prospective study in 25 patients, with 14 cysts measured in vivo and 13 postoperatively, the technique achieved an overall accuracy of 95%, with a 95%confidence interval of 78–99%, in cysts with definitive diagnosis.