We develop an analytical theory for quantum phase transitions driven by disorder in magnets and superconductors. We study these transitions with a cavity approximation which becomes exact on a Bethe lattice with large branching number. We find two different disordered phases, characterized by very different relaxation rates, which both exhibit strong inhomogeneities typical of glassy physics.