A supernova occurs when a massive star exhausts its fuel and its core collapses under the force of gravity, resulting in an explosive blast that sends the star's outer layers into space.