We present an effective medium theory that explains the disorder-induced transition into a phase of quantized conductance, discovered in computer simulations of HgTe quantum wells. It is the combination of a random potential and quadratic corrections proportional to p2 sigma(z) to the Dirac Hamiltonian that can drive an ordinary band insulator into a topological insulator (having an inverted band gap). We calculate the location of the phase boundary at weak disorder and show that it corresponds to the crossing of a band edge rather than a mobility edge. Our mechanism for the formation of a topological Anderson insulator is generic, and would apply as well to three-dimensional semiconductors with strong spin-orbit coupling.