Paradoxically, it is the Sun's gravity that keeps the planets in orbit around it, just as the Earth's gravity keeps the Moon and satellites in orbit around it. The reason they do not just fall into the Sun is that they are traveling fast enough to continually "miss" it.
An analogy helps to explain this: if you throw a rock out from the top of a high tower, it will travel a certain distance before curving down and hitting the Earth. Once thrown, the rock has inertia and would continue in a straight line of motion if there were not some force (gravity) pulling it down. The faster you throw the rock out, the further it travels, until eventually, if you could throw it fast enough (and assuming no air resistance), it would travel all the way around the Earth (and hit you in the back!). The rock is therefore now in orbit: it is still always falling towards the Earth, but the round surface of the Earth is falling away just as fast. Throw the rock a little faster and it would still travel around the Earth but at a higher orbit. If you could throw the rock at what is called the "escape velocity", it would break away from the gravity of the Earth completely and never fall back.
The reason the planets are traveling at just that speed which allows them to orbit the Sun (and not spiral into it or whirl away into space) is not a coincidence or evidence of divine intervention, but goes back to when the Solar System was just a spinning cloud of gas and dust. Everything that was spinning slowly was incorporated into the Sun itself under the force of gravity
; everything that was spinning too fast escaped into outer space; everything else remained in orbit around the Sun and gradually coalesced into the planets, retaining its speed of spin and therefore its orbit (encountering little resistance in the near-vacuum of space).
Because the Sun and planets all formed from the same spinning nebular cloud, this is also why they all rotate in the same direction. As the nebula continued to contract under the influence of gravity it rotated faster and faster due to the conservation of angular momentum. Centrifugal effects caused the spinning cloud to flatten into a flattish disk with a dense bulge at its center (which would coalesce into the Sun). This is why the planets orbit the Sun in a more or less flat plane, known as the ecliptic.
In a simple system, the orbit of a planet around a star would be a perfect circle, but the gravitational influence of other large bodies in the system (in our case, Jupiter and the other gas giants) perturbs the circular orbits into elliptical ones.