The aurora borealis is caused by charged particles (mainly electrons and protons) from the Sun colliding with gas molecules in Earth's atmosphere.
Here's the chain: The Sun emits a stream of particles called the **solar wind**. Earth's magnetic field deflects most of them, but near the poles the field lines converge and funnel particles down into the upper atmosphere (~100–300 km up). When these particles collide with oxygen and nitrogen, they excite the atoms, which release energy as light. Different gases produce different colors: oxygen at ~60 miles → green; oxygen at ~200 miles → red; nitrogen → blue/purple.