By tuning the metal ratio, a Z-scheme g-C 3 N 4 /MgAlFeO nanorod composite was prepared in situ. The nitrogen photofixation performance under visible light was tested to evaluate the performance of the prepared catalysts. Strong electronic coupling, as evidenced by the XPS, PL and EIS results, exists between the two components in the g-C 3 N 4 /Mg 1.1 Al 0.3 Fe 0.2 O 1.7 heterojunction photocatalysts, leading to a more effective separation of photogenerated electron-hole pairs and faster interfacial charge transfer, causing the higher activity and stability for N 2 photofixation. Neat MgAlFeO shows almost no N 2 photofixation activity. However, with the MgAlFeO mass percentage of 23.6%, the as-prepared heterojunction photocatalyst exhibits the highest NH 4 + generation rate under visible light, which is 3.5-fold greater than that of individual g-C 3 N 4 . A possible Z-scheme mechanism is proposed.