  The origin of the observed large scale magnetic fields in the Universe is a
mystery. The seed of these magnetic fields has been attributed to physical
process in the early universe. In this work we provide a mechanism for the
generation of a primordial magnetic field in the early universe via the Weibel
instability in the quark gluon plasma. The Weibel instability occurs in the
plasma if there is an anisotropy in the particle distribution function of the
particles. In early universe, the velocity anisotropy required for Weibel
instability to operate is generated in the quark gluon plasma by the collapse
of closed $Z(3)$ domain walls that arise in the deconfined phase of the QCD
(above $T\sim 200$ MeV). Such large domains can arise in the context of certain
low energy scale inflationary models. The closed domains undergo supersonic
collapse and the velocity anisotropy is generated in the shocks produced in the
wake of the collapsing domain walls. This results in a two stream Weibel
instability in the ultra-relativistic quark gluon plasma. The instability in
turn generates strong magnetic fields in the plasma. We find that the field
strengths generated can be comparable to the equipartition energy density at
the QCD scale which is of the order of $10^{18}$ G.
