The origin of major volatiles nitrogen, carbon, hydrogen, and sulfur in planets is critical for understanding planetary accretion, differentiation, and habitability. However, the detailed process for the origin of Earth's major volatiles remains unresolved. Nitrogen shows large isotopic fractionations among geochemical and cosmochemical reservoirs, which could be used to place tight constraints on Earth's volatile accretion process. Here we experimentally determine N-partitioning and -isotopic fractionation between planetary cores and silicate mantles. We show that the core/mantle N-isotopic fractionation factors, ranging from -4 parts per thousand to +10 parts per thousand, are strongly controlled by oxygen fugacity, and the core/mantle N-partitioning is a multi-function of oxygen fugacity, temperature, pressure, and compositions of the core and mantle. After applying N-partitioning and -isotopic fractionation in a planetary accretion and core-mantle differentiation model, we find that the N-budget and -isotopic composition of Earth's crust plus atmosphere, silicate mantle, and the mantle source of oceanic island basalts are best explained by Earth's early accretion of enstatite chondrite-like impactors, followed by accretion of increasingly oxidized impactors and minimal CI chondrite-like materials before and during the Moon-forming giant impact. Such a heterogeneous accretion process can also explain the carbon-hydrogen-sulfur budget in the bulk silicate Earth. The Earth may thus have acquired its major volatile inventory heterogeneously during the main accretion phase.