Heteroatom-doped carbon nitride (C3N4) with a built-in electric field can reinforce the carrier separation; however, the stability will be greatly reduced due to the loss of surface-doped atoms. Here, molecule self-assembly, as a facile bottom-up approach, is explored for the synthesis and oxygen doping of C3N4. The obtained C3N4 presents a porous and ultrathin structure and oxygen deep-doping, which generate abundant nitrogen vacancies and a stable built-in electric field. Toward photocatalytic hydrogen evolution, the ultrathin and oxygen deep-doped C3N4 exhibits a 3.5-fold higher activity than bulk C3N4 under simulated sunlight, and 3.6 times higher stability than the oxygen surface-doped counterpart within five cycles. Femtosecond transient absorption spectroscopy indicates the improved carrier separation, and density functional theory (DFT) calculation reveals the promoted H2O adsorption and activation under the built-in electric field, which contribute to the excellent photocatalytic performance of oxygen deep-doped ultrathin C3N4.