The petrology record on the Moon suggests that a cataclysmic spike in the cratering rate occurred approximately 700 million years after the planets formed; this event is known as the Late Heavy Bombardment (LHB). Planetary formation theories cannot naturally account for an intense period of planetesimal bombardment so late in Solar System history. Several models have been proposed to explain a late impact spike, but none of them has been set within a self-consistent framework of Solar System evolution. Here we propose that the LHB was triggered by the rapid migration of the giant planets, which occurred after a long quiescent period. During this burst of migration, the planetesimal disk outside the orbits of the planets was destabilized, causing a sudden massive delivery of planetesimals to the inner Solar System. The asteroid belt was also strongly perturbed, with these objects supplying a significant fraction of the LHB impactors in accordance with recent geochemical evidence. Our model not only naturally explains the LHB, but also reproduces the observational constraints of the outer Solar System.