We present numerical simulations of disc–planet interactions where the planet opens a gravitationally unstable gap in an otherwise gravitationally stable disc. In our disc models, where the outer gap edge can be unstable to global spiral modes, we find that as we increase the surface density scale the gap becomes more unstable and the planet migrates outwards more rapidly. We show that the positive torque is provided by material brought into the planet’s co-orbital region by the spiral arms. This material is expected to execute horseshoe turns upon approaching the planet and hence torque it. Our results suggest that standard type II migration, applicable to giant planets in non-self-gravitating viscous discs, is likely to be significantly modified in massive discs when gravitational instabilities associated with the gap occur.