The force of gravity decreases very rapidly with distance, since force is inversely proportional to distance2 . The Sun is much further away from the Moon than the Earth, so its gravitational attraction isn't strong enough to overcome the pull of the Earth's gravity, despite the Sun having greater mass.