We present a model for the formation of the Magellanic Stream (MS) due to ram pressure stripping. We model the history of the Small and Large Magellanic Clouds in the recent cosmological past in a static Milky Way potential with diffuse halo gas, using observationally motivated orbits for the Magellanic Clouds derived from HST proper motions within the potential of the Milky Way. This model is able to reproduce the trailing arm but does not reproduce the leading arm feature, which is common for models of the stream formation that include ram pressure stripping effects. Our model produces a good match to observations (including the densities and line-of-sight velocities of the stream, as well as the positions and velocities of the satellites at present day) when we include a diffuse halo component for the Milky Way. From analyzing our grid of models, we find that there is a direct correlation between the observed stream length in our simulations and the mass of the Milky Way. For the observed MS length, the inferred Milky Way mass is 1.5 ± 0.3 × 10 12 𝑀 , which agrees closely with other independent measures of the Milky Way mass. We also discuss the MS in the context of HI streams in galaxy clusters, and find that the MS lies on the low-mass end of a continuum from Hickson groups to the Virgo cluster. As a tracer of the dynamical mass in the outer halo, the MS is a particularly valuable probe of the Milky Way's potential.