This study involved the synthesis of a novel composite gel consisting of chitosan modified diatomite (DE/CS), sodium alginate (SA), and polyethyleneimine (PEI) (DE/CS-PEI@SA) using the ion crosslinking method. The micro characteristics of the composite gels were examined through scanning electron microscopy, X-ray diffraction, differential scanning calorimetry/thermal gravimetric analysis, and Brunauer-Emmett-Teller systems. Their adsorption properties and mechanisms towards copper Cu(II) and lead Pb(II) ions were investigated using infrared, X-ray photoelectron spectroscopy, energy dispersive spectroscopy, and Zeta potential analyses. The DE/CS-PEI@SA composite gels exhibit numerous uniform folds on its surface, boasting a specific surface area of 18.96 m2/g and a pore size ranging from 1.5 to 80.0 nm, demonstrating robust thermal stability pre- and post- adsorption. Notably, these composite gels demonstrate impressive adsorption capacities for Cu(II) (174.39 mg/g) and Pb(II) (295.04 mg/g), respectively. The integration of DE/CS and PEI within the composite gel contributes to a complex pore structure and a multitude of accessible. The adsorption behavior of the composite gel is accurately characterized by the pseudo-second-order kinetic model and Langmuir model. The predominant adsorption mechanism involves single-molecule chemisorption, involving coordination adsorption, ion exchange, and electrostatic attraction. The composite gel demonstrates notable efficiency in adsorption, cost-effectiveness, and ease of separation, rendering it a viable option for wastewater treatment applications.