The merger of two neutron stars launches a relativistic jet, which must be driven by a strong large-scale magnetic field. However, the magnetohydrodynamical mechanism required to build up this magnetic field remains uncertain. By performing an ab initio super-high-resolution neutrino-radiation magnetohydrodynamics merger simulation in full general relativity, we show that the αΩ dynamo mechanism, driven by the magnetorotational instability, builds up the large-scale magnetic field inside the long-lived remnant of the binary neutron star merger. As a result, the magnetic field induces a Poynting-flux-dominated relativistic outflow with an isotropic equivalent luminosity of ~1052 erg s−1 and a magnetically driven post-merger mass ejection of ~0.1 M⊙. Therefore, the magnetar hypothesis, in which an ultra-strongly magnetized neutron star drives a relativistic jet in binary neutron star mergers, is possible. Magnetars can be the engines of short, hard gamma-ray bursts, and they should be associated with very bright kilonovae, which current telescopes could observe. Therefore, this scenario is testable in future observations.