How does the mass of the moon and the earth help the moon stay in its orbit around the earth?

the gravitational attraction of the masses is what holds the moon in orbit

gravity provides the centripetal force for the circular (mostly) path