When a spacecraft launches on a mission to another planet it must first break free of the Earth’s gravitational field. Once it has done that, it enters interplanetary space, where the dominant force is the gravitational field of the Sun.
The spacecraft begins to follow a curving orbit, around the Sun, which is similar to the orbit of a comet. When this orbit brings it close to its target destination the spacecraft must fire a retrorocket to slow down and allow itself to be captured by the gravitational field of its target. The smaller the target, the more the spacecraft must slow down.
Sometimes passing a planet can result in the spacecraft being accelerated, even without the spacecraft firing any of its thrusters. This is known as the 'slingshot' effect. Such 'gravity assist' manoeuvres are now a standard part of spaceflight and are used by almost all ESA interplanetary missions. They take advantage of the fact that the gravitational attraction of the planets can be used to change the trajectory and speed of a spacecraft.
The amount by which the spacecraft speeds up or slows down is determined by whether it is passing behind or in front of the planet as the planet follows its orbit. When the spacecraft leaves the influence of the planet, it follows an orbit on a different course than before.
ESA’s comet-chasing Rosetta mission launched in 2004 and is using slingshot manoeuvres to reach its destination, Comet 67P/Churyumov-Gerasimenko, in 2014. It has received gravitational ‘kicks’ from close flybys of Mars (2007) and Earth (2005, 2007 and 2009). Rosetta has also made close flybys of two asteroids.