Current models of magnetars require extremely strong magnetic fields to explain their observed quiescent and bursting emission, implying that the field strength within the star's outer crust is orders of magnitude larger than the dipole component inferred from spin-down measurements. This presents a serious challenge to theories of magnetic field generation in a proto-neutron star. Here, we present detailed modeling of the evolution of the magnetic field in the crust of a neutron star through 3D simulations. We find that, in the plausible scenario of equipartition of energy between global-scale poloidal and toroidal magnetic components, magnetic instabilities transfer energy to nonaxisymmetric, kilometer-sized magnetic features, in which the local field strength can greatly exceed that of the global-scale field. These intense small-scale magnetic features can induce high-energy bursts through local crust yielding, and the localized enhancement of Ohmic heating can power the star's persistent emission. Thus, the observed diversity in magnetar behavior can be explained with mixed poloidal−toroidal fields of comparable energies.neutron stars | magnetars | pulsars | magnetohydrodynamics A n estimate of the magnetic field intensity in a neutron star can be obtained by assuming that the observed spin-down is caused by electromagnetic radiation from a dipolar magnetic field (1). Neutron stars for which this estimate exceeds the quantum electrodynamic (QED) magnetic field 4.4 × 10 13 G are conventionally called magnetars, and typically exhibit highly energetic behavior, as in the case of anomalous X-ray pulsars and soft γ-ray repeaters (2, 3). Puzzlingly, not all high magnetic field neutron stars exhibit energetic behavior (4), and, conversely, "magnetar-like" activity has been observed in pulsars for which this field estimate is below (5) or only marginally above the QED magnetic field (6-8). Furthermore, despite the high thermal conductivity of neutron stars' solid outer crusts (9), observations of their thermal emission indicate that, in some cases, the surface is highly anisothermal (10), with kilometer-sized "hot spots" thought to be produced by smallscale magnetic features (11). Phase-resolved spectroscopy has revealed that some magnetars have small-scale magnetic fields whose strength exceeds their large-scale component by at least an order of magnitude (12, 13), which can be correlated with outbursting events (14). These observations all imply that the magnetic field structure in magnetars is more complicated, and varied, than the traditional picture of a simple inclined dipole.The origin of the extreme magnetic fields in these objects, which are the strongest found in nature, is uncertain. Even if magnetic flux were exactly conserved during the star's formation, the resulting field would not exceed 10 13 G. It seems likely, then, that the strong fields in magnetars must result from a combination of differential rotation and dynamo action before the formation of the crust (15). Dynamo models generally predict ma...