The study compared the effects of erector spinae plane block (ESPB) and thoracic paravertebral block (TPVB) on the perioperative pain management of thoracoscopic lobectomy in 99 patients with space-occupying lung lesions from September 2024 to June 2025. Patients were randomly divided into three groups: control, ESPB and TPVB, with comparable baseline data such as sex, age, body mass index or the duration of the operation. The ESPB and TPVB groups had lower visual analog scale (VAS) pain scores at rest and with cough at 2, 4, 8, 16, and 24 hours after surgery compared to the control group (p < 0.05), with TPVB achieving the best results (p < 0.05). The TPVB group showed lower heart rate and mean arterial pressure than ESPB at 2 and 4 hours after surgery (p < 0.05) and lower opioid consumption, shorter time to first ambulation, hospital stay, and duration of drainage tube than the other groups (p < 0.05). Adverse reaction rates were similar in all groups (p > 0.05). The level of pain was positively correlated with the time of first getting up, the duration of hospitalization and the drainage tube (p < 0.05). Both TPVB and ESPB alleviate postoperative pain, reduce stress responses, and shorten recovery, with TPVB providing better early analgesia and hemodynamic stability. The study is registered at www.chictr.org.cn under ChiCTR2100054074.