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.