The stability of a sheared magnetic field is analyzed in two-dimensional ma
gnetohydrodynamics with resistive and viscous dissipation. Using a multiple
-scale analysis, it is shown that at large enough Reynolds numbers the basi
c state describing a motionless fluid and a layered magnetic field, becomes
unstable with respect to large scale perturbations. The exact expressions
for eddy-viscosity and eddy-resistivity are derived in the nearby of the cr
itical point where the instability sets in, in this marginally unstable cas
e the nonlinear phase of perturbation growth obeys to a Cahn-Hilliard-like
dynamics characterized by coalescence of magnetic islands leading to a fina
l new equilibrium state. High resolution numerical simulations confirm quan
titatively the predictions of multiscale analysis.