Abstract Background: Total hip arthroplasty (THA) is widely acknowledged as the primary treatment for end-stage joint diseases.Perfect postoperative analgesia can significantly decrease the incidence of adverse complications after hip replacement.We hypothesized that administering Esketamine in patient-controlled analgesia after hip replacement can alleviate postoperative pain and improve sleep quality in patients. Methods: We recruited 72 patients undergoing unilateral total hip arthroplasty under combined general and peripheral nerve block anaesthesia. The patients were assigned to either the F-D group (fentanyl combined with dexmedetomidine,n=34) or the Es-D group (Esketamine combined with dexmedetomidine,n=38) using a random number table method. The primary outcome measures included the time to the first use of rescue analgesics and the dose of rescue analgesics. Results: Patients in the Es-D group had a significantly shorter time to request the first postoperative rescue analgesic than those in the F-D group (P<0.05). The dose of rescue analgesics used in the Es-D group was considerably lower than that in the F-D group (P<0.05).The two groups had no significant differences in postoperative sleep quality and adverse reactions. However, four cases of urinary retention were observed in the F-D group, which was significantly higher than in the Es-D group (P<0.05). Conclusion: Esketamine provided a better analgesic effect than fentanyl and did not increase postoperative adverse reactions but can not improve the sleep quality for patients. Trial registration:The clinical trial was registered at the China Clinical Trial Registration Center on 24/02/2021. (ChiCTR2100043649).http://www.chictr.org.cn/showproj.aspx?proj=122393.