We study the evolution of phase-transitiongenerated cosmic magnetic fields coupled to the primeval cosmic plasma in the turbulent and viscous free-streaming regimes. The evolution laws for the magnetic energy density and the correlation length, both in the helical and the non-helical cases, are found by solving the autoinduction and Navier-Stokes equations in the mean-field approximation. Analytical results are derived in Minkowski spacetime and then extended to the case of a Friedmann universe with zero spatial curvature, both in the radiation-and the matterdominated era. The three possible viscous free-streaming phases are characterized by a drag term in the Navier-Stokes equation which depends on the free-streaming properties of neutrinos, photons, or hydrogen atoms, respectively. In the case of non-helical magnetic fields, the magnetic intensity B and the magnetic correlation length ξ B evolve asymptotically with the temperature, T , asHere, T i , N i , and v i are, respectively, the temperature, the number of magnetic domains per horizon length, and the bulk velocity at the onset of the particular regime. The coefficients κ B , κ ξ , 1 , 2 , 3 , and 4 , depend on the index of the assumed initial power-law magnetic spectrum, p, and on the particular regime, with the order-one constants κ B and κ ξ depending also on the cutoff adopted for the initial magnetic spectrum. In the helical case, the quasi-conservation of the magnetic helicity implies, apart from logarithmic corrections and a factor proportional to the initial fractional helicity, power-like evolution laws equal to those in the non-helical case, but with p equal to zero.