(We promise no spam).
When the terrestrial planets were forming, they remained immersed in a disk of gas and dust. The gas was partially supported by pressure and so did not orbit the Sun as rapidly as the planets. The resulting drag and, more importantly, gravitational interactions with the surrounding material caused a transfer of angular momentum , and as a result the planets gradually migrated to new orbits. Models show that density and temperature variations in the disk governed this rate of migration,   but the net trend was for the inner planets to migrate inward as the disk dissipated, leaving the planets in their current orbits.