We prove the $p$-curvature conjecture for rank two vector bundles with connection on generic curves, by combining deformation techniques for families of varieties and topological arguments.