Postoperative poor sleep quality and decreased gastrointestinal motility function are common clinical problems. This study investigated the effects of dexmedetomidine (DEX) combined with sufentanil for patient-controlled analgesia (PCA) on postoperative sleep quality and gastrointestinal motility function after surgery in patients with colorectal cancer. Patients undergoing colorectal cancer surgery were randomly divided into three groups, DEX 0, 200, or 400 μg, each combined with sufentanil 150 μg for PCA immediately after surgery. The primary outcome was sleep quality in the first 7 days after surgery based on the Athens Insomnia Scale (AIS) score. The secondary outcome was postoperative gastrointestinal motility recovery evaluated by the time of first flatus, first feces and first diet. Postoperative pain intensity, side effects and the length of postoperative hospital stay were also compared among groups. The study was registered with the Chinese Clinical Trial Registry (https://www.chictr.org.cn/enIndex.aspx, ChiCTR2000032601). Ultimately, 210 cases were included. Sleep quality was better in the DEX 200 μg group and DEX 400 μg group than in the DEX 0 μg group. Overall, in the DEX 200 μg group and DEX 400 μg group, the AIS score ( < 0.05) and the incidence of sleep disturbance (7.3%, 4.5% vs. 19.6%, < 0.001) were lower than those in the DEX 0 μg group in the first 7 days after surgery. There were no significant differences in postoperative gastrointestinal motility among the three groups in the total surgical categories ( > 0.05). In the laparoscopic surgery patients of each group, the time of postoperative first flatus ( = 0.02) and first feces ( = 0.01) was significantly longer in the DEX 400 μg group than in the DEX 0 μg group. There were no differences in postoperative pain intensity, side effects or length of postoperative hospital stay ( > 0.05). The continuous infusion of DEX (200 or 400 μg) for PCA significantly improved postoperative sleep quality after colorectal cancer surgery. DEX (200 μg) was better at improving postoperative sleep quality without affecting gastrointestinal motility function than DEX (400 μg) in patients who underwent laparoscopic colorectal cancer surgery.