The scientists think the frozen sperm belonged to a leech-like creature possibly related to crayfish worms and managed to stay well-preserved because it was encased in a protective casing, the Washington Post reports:
The ancient worm secretes a cocoon, about 2 millimeters around, which then typically serves as a protective housing for an egg and sperm when the worm reproduces. The cocoon is formed by a sticky mucus that takes several days to harden, but once it does, biological material, such as sperm, can be trapped along its walls.
This is a diagram of the leech sex that created the sperm and the cocoon:
Source: Biology Letters
Sperm specimens, because they're quite delicate, usually don't survive for this long, one of the study's authors told the Guardian.
“It was an accidental find,” Benjamin Bomfleur, a palaeobotanist at the Swedish Museum of Natural History in Stockholm, told the Guardian. “We were analysing the fragments to get a better idea of the structure of the cocoon. When we zoomed into the images, we started noticing these tiny biological structures that look like sperm.”
The type of cocoon that kept the sperm from completely deteriorating all these years could provide other ancient fossils, the scientists wrote.