One possibility is that the Moon was originally an independent dwarf planet that was captured by Earth’s gravity. Mars is thought to have snagged its two moons, Phobos and Deimos, this way.
Alternatively, the Moon and Earth could have formed together, from the same dust and gas. This is more consistent with the Moon’s orbit but it doesn’t explain why it is much less dense than Earth.
But the theory currently preferred by astronomers is that a Mars-sized planet, called Theia, collided with Earth 4.5 billion years ago. The Moon was formed from the lighter crustal elements that were blasted into space by the impact, leaving Earth’s denser core behind.