In this study, we developed a fluorescent aptasensor based on Fe3O4/Au/g-C3N4 and a FAM-labeled aptamer (FAM-SMZ1S) against sulfamethazine (SMZ) for the specific and sensitive detection of SMZ in food matrix. The FAM-SMZ1S was adsorbed by the Fe3O4/Au/g-C3N4 via π–π stacking and electrostatic adsorption, serving as a basis for the ultrasensitive detection of SMZ. Molecular dynamics was used to explain the reasons why SMZ1S and SMZ were combined. This aptasensor presented sensitive recognition performance, with a limit of detection of 0.16 ng/mL and a linear range of 1–100 ng/mL. The recovery rate ranged from 91.6% to 106.8%, and the coefficient of variation (CV) ranged from 2.8% to 13.4%. In addition, we tested the aptasensor for the monitoring of SMZ in various matrix samples, and the results were well-correlated (R2 ≥ 0.9153) with those obtained for HPLC detection. According to these results, the aptasensor was sensitive and accurate, representing a potentially useful tool for the detection of SMZ in food matrix.