Near-infrared light (NIR)-driven photoelectrochemical (PEC) processes are mainly faced with the limitation of weak photocurrents. Here, N-deficient B-doped g-C3N4/CdS (NB-g-C3N4/CdS) is proposed to construct a NIR-driven PEC biosensor assisted by CRISPR-Cas12a system for the determination of microRNA-21 (miRNA-21). To promote the optical absorption as well as the separation of photogenerated electrons and holes of g-C3N4, NB-g-C3N4/CdS is constructed via engineering the electronic and band structure in terms of N defect, B doping, and heterojunction, achieving high PEC performance. To obtain the high luminescence efficiency for exciting NB-g-C3N4/CdS under NIR, the core–shell NaYF4:Yb3+, Tm3+@NaYF4 upconversion nanoparticles (UCNPs) with repaired defects are prepared. Furthermore, the rolling circle amplification (RCA)-assisted CRISPR-Cas12a system is integrated to fragment the DNA on UCNPs, achieving sensitive detection of miRNA-21. On the one hand, the uncleavaged signal probes on UCNPs combined with NB-g-C3N4/CdS through π–π stacking interaction, generating photocurrents under the irradiation of NIR. On the other hand, the cleavaged signal probes which cannot link with NB-g-C3N4/CdS exhibited the fluorescence (FL) signals. The proposed PEC-FL dual-mode biosensor provides a mutual authentication of testing results and demonstrates ultrasensitivity (the detection limit of 1.1 fM for PEC mode and 7.0 fM for FL mode) and excellent specificity, which is promising in the clinical analysis of miRNA.