Gravity keeps planets in orbit by providing the centripetal force needed to balance their inertia, causing them to follow curved paths around the Sun.