Dalbergia hancei Benth (D. hancei) is a plant belonging to the Fabaceae family. It has analgesic and anti-inflammatory effects and is used by the Zhuang people to relieve pain. However, the mechanism underlying its analgesic effects remains unclear. This study investigates the analgesic effect of D. hancei based on metabolomics to explain the mechanism of its analgesia from a metabolomics perspective. The analgesic effect was evaluated through the acetic acid-induced writhing test and hot plate test. Three treatment groups received different dosages of D. hancei (0.91 g/kg, 3.64 g/kg, 7.28 g/kg). Its analgesic mechanism was investigated using analgesic behavioral tests and metabolomics. The results of analgesic behavioral experiments showed that all dose groups of D. hancei could relieve pain. A total of eight differential metabolites were identified in the metabolomics results. These biomarkers are associated with five metabolic pathways. Following treatment with D. hancei, eight differential metabolites were identified as regulated, primarily affecting amino acid metabolism, pantothenate and CoA biosynthesis, and steroid hormone biosynthesis. This study revealed the mechanism of analgesia from a metabolomic perspective to provide a basis for screening TCM drugs in pain treatment.