To compare the effects of preoperative ultrasound-guided erector spinae plane block (ESPB) and preoperative wound infiltration on perioperative opioid consumption and postoperative pain in thoracotomy. Randomised controlled trial. Department of Anesthesiology, Cancer Hospital, Chinese Academy of Medical Sciences and Peking Union Medical College, from October 2018 to April 2019. Sixty adult patients undergoing open esophagectomy were allocated randomly into two groups: experimental group (ultrasound-guided ESPB group, n = 30) and control group (wound infiltration group, n = 30). In ultrasound-guided ESPB group (group EB), ESPB with 20 ml of 0.5% ropivacaine was performed at the level of thoracic 5 transverse process. Whereas, in wound infiltration group (group WI), 20 ml of 0.5% ropivacaine was injected subcutaneously along the marked line of skin incision for surgery and chest tube placement. The perioperative opioid consumption, pain scores at rest and during coughing immediately after surgery, at postoperative day (POD) 1 and POD 2, consumption of rescue analgesic tramadol and postoperative opioid-related adverse events were all assessed. Compared with group WI, the intraoperative and postoperative opioid consumptions, postoperative tramadol consumption were significantly less in group EB (p <0.05). Moreover, the postoperative pain scores immediately after surgery, at POD 1 and POD 2, were all lower in group EB compared to group WI (p <0.05). Significantly, the postoperative incidence of nausea and vomiting was lower in group EB than that in group WI (p = 0.021). Compared to wound infiltration with local anesthetics, preoperative ultrasound-guided ESPB could significantly reduce perioperative opioid consumption, provide a better postoperative analgesia and reduce opioid-related adverse events in thoracotomy.