A visible-light-driven heterostructured AgI/g-C3N4 was prepared by a deposition-precipitation method. The composition, structure, morphology, and optical properties of the photocatalyst were characterized by Brunauer-Emmett-Teller method (BET), X-ray powder diffraction (XRD), Fourier transform-infrared spectroscopy (FTIR), X-ray photoelectron spectroscopy (XPS), transmission electron microscope (TEM), scanning electron microscope (SEM), UV–vis diffused reflectance spectroscopy (DRS), photoluminescence spectroscopy (PL), photocurrent, and electrochemical impedance spectroscopy (EIS), respectively. AgI/g-C3N4 composite photocatalysts exhibited higher photocatalytic activities than those of AgI nanoparticles and g-C3N4 in the degradation of diclofenac (a model anti-inflammatory medicine) under visible light irradiation (λ≥400nm). When the mass molar ratio of AgI was 45% in AgI/g-C3N4, the reaction rate constant of diclofenac degradation reached 0.561min−1, which was almost 12.5 and 43.2 times higher than that achieved by AgI (0.045min−1) and g-C3N4 (0.013min−1). The h+ and O2- were pinpointed as the main reactive species in the photocatalytic reaction using their obligate radical scavengers. Diclofenac was completely degraded and partly mineralized during the photodegradation. The main intermediates were determined by liquid chromatograph mass spectrometer (LC-MS), and toxicological assessments were carried out to evaluate the change of toxicity in the degradation process. In addition, the photocatalysts showed excellent stability over multiple reaction cycles. Finally, a possible photocatalytic and charge separation mechanism was proposed.