An ionic liquid (IL, [DMAPA]HSO4) was prepared to facilitate the removal of heavy metals by hydrothermal carbonization (HTC) in sewage sludge (SS) and to obtain a positive energy recovery (ER, (Energyoutput/Energyinput − 1) > 0). The results found that the removal efficiencies of the Fe, Mn, Zn, Co, and Cd from SS exceeded 75 % with positive ER (6 %) at 20 wt% IL dosage (IL:SS). IL promoted the HTC reactions of proteins and polysaccharides to produce fixed carbon and small molecule polymers. The process mainly relies on IL to catalyze the dehydration and graphitization of SS and to destroy the heavy metal binding sites such as carboxyl and hydroxyl groups. Additionally, IL aids in constructing the macropore structures in hydrochar, thereby facilitating the release of heavy metals and water during the HTC process. This discovery holds promise for removing heavy metals from SS by one-pot HTC processes with positive energy recovery.