International audienceAims.We have studied the chemistry of nitrogen-bearing species during the initial stages of protostellar collapse, with a view to explaining the observed longevity of N2H+ and NH3 and the high levels of deuteration of these species. Methods: .We followed the chemical evolution of a medium comprising gas and dust as it underwent free-fall gravitational collapse. Chemical processes which determine the relative populations of the nuclear spin states of molecules and molecular ions were included explicitly, as were reactions which lead ultimately to the deuteration of the nitrogen-containing species N2H+ and NH3. The freeze-out of "heavy" molecules on to dust grains was taken into account. Results: .We found that the times...