Graphitic carbon nitride with nitrogen vacancies was successfully synthesized by the three-step method for the calcination of melamine, following urea-assisted hydrothermal and jacjoin calcination approach. The structural, surface, optical and electric properties were characterized by XRD, FT-IR, SEM, TEM, UV–Vis DRS, PL, N2 physical adsorption/desorption and electrochemical methods, which proved that this strategy of modifying g-C3N4 by nitrogen vacancies not only increased the specific surface area, exposed more active sites, but also inhibited the recombination of photogenerated carriers on the surface of photocatalysts, resulting in the enhancement of photocatalytic and electrocatalytic performances. The photocatalytic activities were measured under visible light irradiation (λ>420λ>420nm), and their degradation efficiencies could be achieved for 99.8%, 55%, 100% and 99.7% corresponding to that of rhodamine B, acid orange II, methyl orange and methylene blue, respectively. The trapping experiments demonstrated that •O−2∙O−2 played an important role in the degradation process. In addition, being an active electrocatalyst, nitrogen-deficient g-C3N4 showed a lower Tafel slope, smaller overpotential and the more effective electrochemical surface area compared with that of bare g-C3N4 in neutral media. This work underlines the importance of defect engineering to promote catalytic performance, which can provide a simple and efficient way for modifying g-C3N4 and other N-based catalysts.