We present time-dependent axisymmetric magnetohydrodynamic simulations of the interaction of a relativistic magnetized wind produced by a proto-magnetar with a surrounding stellar envelope, in the first $sim 10$ seconds after core collapse. We inject a super-magnetosonic wind with $dot E = 10^{51}$ ergs s$^{-1}$ into a cavity created by an outgoing supernova shock. A strong toroidal magnetic field builds up in the bubble of plasma and magnetic field that is at first inertially confined by the progenitor star. This drives a jet out along the polar axis of the star, even though the star and the magnetar wind are each spherically symmetric. The jet has the properties needed to produce a long-duration gamma-ray burst (GRB). At $sim 5$ s after core bounce, the jet has escaped the host star and the Lorentz factor of the material in the jet at large radii $sim 10^{11}$ cm is similar to that in the magnetar wind near the source. Most of the spindown power of the central magnetar escapes via the relativistic jet. There are fluctuations in the Lorentz factor and energy flux in the jet on $sim 0.01-0.1$ second timescale. These may contribute to variability in GRB emission (e.g., via internal shocks).