  We study the stability of topological order against local perturbations by
considering the effect of a magnetic field on a spin model -- the toric code --
which is in a topological phase. The model can be mapped onto a quantum loop
gas where the perturbation introduces a bare loop tension. When the loop
tension is small, the topological order survives. When it is large, it drives a
continuous quantum phase transition into a magnetic state. The transition can
be understood as the condensation of `magnetic' vortices, leading to
confinement of the elementary `charge' excitations. We also show how the
topological order breaks down when the system is coupled to an Ohmic heat bath
and discuss our results in the context of quantum computation applications.
