  We analyze the toric code model in the presence of quenched disorder, which
is introduced via different types of random magnetic fields. In general, close
to a quantum phase transition between a spin polarized phase and a
topologically ordered one, we find that increasing the amount of disorder
favors the topological phase. For some realizations of disorder, topological
order can be robust against arbitrarily strong magnetic fields. In the case of
the toric code in a random \pm h field, we show that the system exhibits a
quantum phase transition to a spin glass phase in an appropriate dual variables
description. The survival of topological order in the spin glass phase is
directly related to the percolation properties of the rigid lattice in the
Edwards-Anderson bimodal spin glass model. According to recent numerical
results for this model [Phys. Rev. B 82, 214401 (2010)], it is likely that the
rigid lattice does not percolate and, as a result, a new intermediate quantum
phase appears in the random-field toric code. In this intermediate quantum
phase, topological order coexists with spin glassiness.
