  We study the decoupling process of neutrinos in the early universe in the
presence of three-flavour oscillations. The evolution of the neutrino spectra
is found by solving the corresponding momentum-dependent kinetic equations for
the neutrino density matrix, including for the first time the proper collision
integrals for both diagonal and off-diagonal elements. This improved
calculation modifies the evolution of the off-diagonal elements of the neutrino
density matrix and changes the deviation from equilibrium of the frozen
neutrino spectra. However, it does not vary the contribution of neutrinos to
the cosmological energy density in the form of radiation, usually expressed in
terms of the effective number of neutrinos, N_eff. We find a value of
N_eff=3.045, in agreement with previous theoretical calculations and consistent
with the latest analysis of Planck data. This result does not depend on the
ordering of neutrino masses. We also consider the effect of non-standard
neutrino-electron interactions (NSI), predicted in many theoretical models
where neutrinos acquire mass. For two sets of NSI parameters allowed by present
data, we find that N_eff can be reduced down to 3.040 or enhanced up to 3.059.
