The gravitational pull of the Sun on the Moon is greater than the pull of the Earth, but the Moon remains in orbit around the Earth because:
1) The Moon and Earth orbit around their common center of mass, which is closer to the Earth due to its greater mass.
2) The centripetal force keeping the Moon in its circular orbit is provided by the Earth's gravitational attraction of the Moon.
3) The center of mass of the Earth-Moon system and the Sun orbit around their common center of mass, which is closer to the Sun due to its overwhelming mass.