We investigate the dynamical evolution of the terrestrial planets during the planetesimal-driven migration of the giant planets. A basic assumption of this work is that giant planet migration occurred after the completion of terrestrial planet formation, such as in the models that link the former to the origin of the late heavy bombardment. The divergent migration of Jupiter and Saturn causes the g5 eigenfrequency to cross resonances of the form g_5=gk with k ranging from 1 to 4. Consequently these secular resonances cause large-amplitude responses in the eccentricities of the terrestrial planets if the amplitude of the g5 mode in Jupiter is similar to the current one. We show that the resonances g_5=g4 and g_5=g3 do not pose a problem if Jupiter and Saturn have a fast approach and departure from their mutual 2:1 mean motion resonance. On the other hand, the resonance crossings g_5=g2 and g_5=g1 are more of a concern: they tend to yield a terrestrial system incompatible with the current one, with amplitudes of the g1 and g2 modes that are too large. We offer two solutions to this problem. The first solution states that a secular resonance crossing can also damp the amplitude of a Fourier mode if the latter is large originally. We show that the probability of the g_5=g2 resonance damping a primordially excited g2 mode in the Earth and Venus is approximately 8%. Using the same mechanism to also ensure that the g_5=g1 resonance keeps the amplitude of the g1 mode in Mercury within 0.4 reduces the overall probability to approximately 5%. However, these numbers may change for different initial excitations and migration speeds of the giant planets. A second scenario involves a “jumping Jupiter” in which encounters between an ice giant and Jupiter, without ejection of the former, cause the latter to migrate away from Saturn much faster than if migration is driven solely by encounters with planetesimals. In this case, the g_5=g2 and g_5=g1 resonances can be jumped over, or occur very briefly. We show that, in this case, the terrestrial system can have dynamical properties comparable to what is exhibited today. In the framework of the Nice model, we estimate that the probability that Jupiter had this kind of evolution is approximately 6%.