A highly sensitive and selective photoelectrochemical (PEC) aptasensor was constructed by Ag nanoparticles sensitized bismuth oxyiodide (AgNPs/BiOI) composites for detecting trace chloramphenicol (CAP). Because the sufficient light utilization of AgNPs and high photoelectrons transfer efficiency of BiOI, AgNPs/BiOI composites exhibited dramatically enhanced PEC performance, which is in favor of realizing efficient CAP detection. Attributed to the specific recognition of modified CAP aptamer, the PEC CAP aptasensor based on the aptamer/AgNPs/BiOI/ITO electrodes performed a wide linear range (1 pM − 20000 pM), a satisfactory detection limit (0.4 pM, S/N = 3), and superior selectivity. In addition, the CAP aptasensor possessed favorable stability and reproducibility, promoting further application of CAP trace detection and providing a foothold for ultrasensitive antibiotic detection and environmental monitoring.