Wetting-drying cycles in the environment could change the inner- or outer-sphere complexation of heavy metal cations on natural organic matter (NOM) and then influence ternary interactions with organic contaminants - a rarely-discussed essential geochemical process. In this work, the sorption of sulfamethoxazole (SMX) on humic acids (HAs) mediated by cations (Cu2+ and Cd2+) was investigated. Considering that outer-sphere complexation could be transformed into inner-sphere complexation during vacuum freeze-drying, the role of inner- or outer-sphere complexation on SMX sorption was explored. The experimental sorption results and density functional theory (DFT) calculations suggested that Cu2+ and Cd2+ sorption on HAs was mainly outer- and inner-sphere complexation, respectively. Cd2+ consistently promoted SMX sorption on HAs, while Cu2+ promoted and inhibited SMX sorption before and after freeze-drying. The structure of HA-Cu complexes with inner-sphere complexation was more compact than those with outer-sphere complexation, which reduced the accessibility of sorption sites for SMX on HA-Cu and inhibited SMX sorption. However, the greater number of coordination sites of Cd2+ may provide more sorption sites and the structure of HA-Cd was looser. These findings provide a groundbreaking understanding of the sorption of organics on natural adsorbents in the presence of cations.