Municipal sewage sludge (MSS) contains significant amounts of trace elements including zinc, copper, cadmium, and lead. This study investigated the behavior of these trace elements in municipal sewage sludge biochar during the pyrolysis of both anaerobically digested and undigested sludge at temperatures ranging from 500 degrees C to 900 degrees C using a rotary pyrolyzer. Microwave plasma-atomic emission spectroscopy (MP-AES) was used to measure the concentrations of trace elements in the biochars. Additional analyses included Fourier-transform infrared spectroscopy (FTIR), thermogravimetric analysis to determine the activation energies, and Brunauer-Emmett-Teller (BET) analysis coupled with scanning electron microscopy to assess the porosity, specific surface area, and morphology at different temperatures. Thermodynamic equilibrium calculations (TECs) were utilized to understand the speciation of trace elements under varying thermal conditions. The results demonstrated that as the pyrolysis temperature increased, both the undigested and digested biochars exhibited higher surface areas and total porosity volumes, along with a decrease in the average pore size. The digested biochar showed a higher surface area and pore volume at 500 degrees C than the undigested biochar. However, both types processed at 900 degrees C had similar average pore diameters of approximately 7.5 nm, according to BET analysis. All biochars had H/C ratios below and around 0.2, indicating strong degradation resistance. TECs results indicated that, at 500 degrees C, the thermal volatility sequence of the trace elements was established as Cr < Ni < Cu < Mn < Zn < Pb < Cd. Consequently, higher temperatures led to reduced concentrations of Cd, Pb, and Zn in all biochars while Cr, Ni, and Cu were largely retained in the biochar. Phosphorous (P) was enriched in the biochars at all temperatures for both MSS, however anaerobically digested MSS biochar exhibiting higher concentration of nutrient such as P, higher porosity and a finer pore structure compared to undigested one. Biochar yield decreases as pyrolysis temperature rises (500-900 degrees C) for both digested (BSS) and undigested (LSS) sludge, with BSS consistently yielding more than LSS.