In present study, an efficient ternary Ag/TiO2/mesoporous g-C3N4 (M-g-C3N4) photocatalyst was successfully synthesized through depositing Ag nanoparticles (NPs) on the surface of TiO2/M-g-C3N4 heterojunction. Ag/TiO2/M-g-C3N4 nanocomposite displayed the highest degradation efficiency for amoxicillin (AMX) compared to TiO2/M-g-C3N4 heterojunction, M-g-C3N4, and bulk-g-C3N4 (B-g-C3N4). The removal efficiency of AMX in real situation, surface water (SW), hospital wastewater (HW), and waste water treatment plant (WWTP) also were studied to illustrate the effectiveness of Ag/TiO2/M-g-C3N4 photocatalysts. The vulnerable atoms in AMX structure were revealed through DFT calculation. Additionally, the dominating active groups produced in time of the photocatalytic procedure were determined on account of free radical trapping experiments and ESR spectra. The mechanism of photocatalytic degradation was proposed and verified. The transfer of the electrons and the inhibition of the recombination of photogenerated electron-holes were enhanced effectively under the synergistic effect of the Ag NPs and TiO2. As a consequence, the catalytic activity of the composite was improved under visible light.