In this chapter we will discuss our current understanding of the late stages of formation of the solar system. We shall focus mainly on dynamical processes that took place after the giant planets (Jupiter, Saturn, Uranus and Neptune) had already formed. We will try to explain how the interaction of the giant planets with the remaining protoplanetary disc has led our planetary system to develop the currently observed dynamical architecture. More precisely, we will discuss the two main phases of planet migration, i.e. (i) gas-driven migration, when enough gas was still present in the system, and (ii) planetesimals-driven migration, that started immediately after the gas was gone. We will show that, during the first migration phase, the outer planets could have reached a stationary, multi-resonant, state, the outermost one being only ∼ 12− 13 AU away from the Sun. Then, during the phase of planetesimals-driven migration, the planets could have had their eccentricities increased by resonance-crossing, a mechanism that leads to a short instability phase and a complete reshaping of the planetary orbits. We will show that this model can explain a number of puzzling problems, such as the orbital parameters of the giant planets, the orbital distribution in the small bodies’ reservoirs and the occurrence of the Late Heavy Bombardment (LHB) of the terrestrial planets. Finally, we will examine the aforementioned dynamical mechanisms in the more general context of Extra-solar planetary systems and we will attempt to develop a general evolution scheme for young planetary systems.