Planetary systems are born in the disks of gas, dust and rocky fragments that surround newly formed stars. Solid content assembles into ever-larger rocky fragments that eventually become planetary embryos. These then continue their growth by accreting leftover material in the disc. Concurrently, tidal effects in the disc cause a radial drift in the embryo orbits, a process known as migration [1][2][3][4] . Fast inward migration is predicted by theory for embryos smaller than three to five Earth masses [5][6][7] . With only inward migration, these embryos can only rarely become giant planets located at Earth's distance from the Sun and beyond 8,9 , in contrast with observations 10 . Here we report that asymmetries in the temperature rise associated with accreting infalling material 11, 12 produce a force (which gives rise to an effect that we call "heating torque") that counteracts inward migration. This provides a channel for the formation of giant planets 8 and also explains the strong planet-metallicity correlation found between the incidence of giant planets and the heavy-element abundance of the host stars 13, 14 .We solve the equations governing the disc hydrodynamics in combination with the equations of radiative transfer. Planets have an angular momentum that increases with their orbital radius. In the case of a nearly circular orbit, the rate of change of angular momentum, or torque, gives the migration rate. Our calculations are performed in three dimensions, yielding a reliable value for the net torque, from which the direction and rate of migration are inferred.Our fiducial computation is one in which a rocky core with 3 Earth masses is located at a distance comparable to that of Jupiter from the Sun and is being bombarded by solid material at a rate that doubles its mass in 100 thousand years. We assume that the gravitational energy of the infalling solid material is transformed entirely into heat and ultimately radiated by the planet 11 . A second computation is performed with the same set up, but without the planet's radiation, in order to distinguish the effects of the heating torque from other torques. We find that the heating torque (defined as the torque difference between cases with accretion turned respectively on and off) has a positive sign (figure 1), which enables it to counteract the effect of the standard, negative torque.The latter includes all torque components of the non-heating case, and is always negative for small 2 mass embryos (typically smaller than 5 M ⊕ , where M ⊕ is the Earth's mass). Thus, the effect of the heating torque is to either slow down the inward migration, cancel it, or reverse its direction.The most important factors governing the strength of the heating torque and thus, the direction of migration, are the accretion rate of the embryo, its mass and the opacity of the disc. For our fiducial values of opacity, disc structure and embryo mass, we find that outward migration occurs for accretion rates corresponding to a mass doubling time less than approximately 60 t...