This work presents a novel hexagonal boron nitride (h-BN) based self-powered photoelectrochemical (PEC) aptasensor for ultrasensitive detection of diazinon (DZN) with excellent photoelectric conversion efficiency. It was the first time that h-BN based materials were applied to PEC aptasensor, in which the construction of Z-scheme heterojunction of h-BN and graphitic carbon nitride (CN) via doping sulfur into h-BN was innovatively proposed. Meanwhile, Au nanoparticles (AuNPs) were utilized for the surface plasmon resonance (SPR) effect and the formation of new recombination centers. The charge transfer mechanism was expounded and verified by the electron spin resonance (ESR) spin-trap technique. The proposed PEC aptasensor for determination of DZN exhibited a wide linear range from 0.01 to 10000 nM and a low detection limit of 6.8 pM with superb selectivity and remarkable stability. Moreover, the constructed PEC aptasensor performed well with excellent recoveries in three different real samples. This work illustrated that PEC aptasensor is a promising alternative to conventional analytical technologies for the detection of DZN and other organophosphorus (OP) pesticides. The designing ideas of the proposed h-BN based material can provide a foothold for the innovative construction of photoactive materials for PEC bioanalysis.