This is the fundamental principle of Newton's Law of Universal Gravitation. Every object in the universe exerts a gravitational force on every other object, and the strength of that force depends on the masses of the objects and the distance between them.
Even in the vast emptiness of space, where there are no other forces to interfere, two masses will inevitably attract each other, pulling them closer together over time.