Ancient people (and not-so-ancient people) thought the end of the world was coming when the sun went dark. Today, we know the celestial cycles that produce a solar eclipse and the earth's shadow that produces a lunar eclipse. But when the world did not end, those ancient people looked for meaning in the events. Many myths grew out of their experiences, which are quite different in various parts of the world.
When something dreadful happens in Norse mythology, you can safely assume Loki had something to do with it. The trickster god managed to father the ultimate world-consuming serpent, the queen of the underworld and a god-slaying giant wolf. That wolf, Fenrir, spawned the eventual doom of both sun and moon in the lupine duo Sköll and Hati. Yes, everything Loki touches turns to Ragnarök.
Sköll doesn’t get to gobble up the sun ‘til the end times arrive—and when he finally sinks his teeth in, the light of the world extinguishes in his grim belly. Meanwhile, Hati eats the moon. Stephen Hawking described the wolves as eclipse monsters in The Grand Design and many other publications follow suit, but not everyone’s convinced. Some commentators, such as skeptic Eve Siebert, argue that the often-cited Old Norse poem Grímnismál merely points to a dark eventuality and not recurrent events. Still, it’s possible the Norse saw these tales of doom reflected in eclipses, or even considered them near misses in an eternal race between light and all-consuming dark.
Read about other eclipse myths from ancient Egypt, Mesopotamia, India, and Persia in an article at Atlas Obscura.