In thermal equilibrium the ground state of the plasma of Standard Model particles is determined by temperature and exactly conserved combinations of baryon and lepton numbers. We show that at non-zero values of the global charges a translation invariant and homogeneous state of the plasma becomes unstable and the system transits into a new state, containing a large-scale magnetic field. The origin of this effect is the parity-breaking character of weak interactions and chiral anomaly. This situation can occur in the early Universe and may play an important role in its subsequent evolution.