Updated on July 18 at 11:45 p.m. ET*

In April 2015, Kaeli Swift laid a dead crow next to a cherry tree—and waited.

Swift, who studies bird behavior at the University of Washington, had previously shown that crows conduct “funerals” by gathering around the corpses of their peers. Now a film crew had come to capture this behavior.

As if on cue, another crow alighted on a nearby branch and gazed at the cadaver beneath it. Instead of cawing from afar, it flew down and approached the body. Swift wasn’t expecting that, and she certainly wasn’t expecting the crow to then droop its wings, erect its tail, and strut in the way crows only do when they’re about to mate. And sure enough, the living bird mounted the dead one.

Crows, like most birds, have no penises. Instead of penetrative sex, they simply bring vents beneath their tails into contact. To do this, a male needs to swivel his tail beneath a female’s, but since the dead crow was lying belly down, that was impossible. “It was like watching a kid standing on a piece of cardboard and trying to pick it up,” Swift says. “It was thrashing about awkwardly.”

As Swift recounted this week in a blog post called “Putting the ‘crow’ in necrophilia,” someone on the film crew earnestly asked if the living crow was giving the stuffed one CPR. She and her supervisor, John Marzluff, exchanged glances, shook their heads, and left “the word ‘copulation’ to hang awkwardly in the air.” And when the shock subsided, the pair began planning experiments to find out how common crow necrophilia actually is, and why it happens. “What better people to have this happen to than a couple of scientists,” she told me. “We can go forth and science.”

For centuries, people have noticed that crows, ravens, jays, and related birds pay attention to the bodies of their dead, by making alarm calls or recruiting other birds to the scene. It’s easy to interpret these “funerals” in the context of grieving or human attitudes to death. But researchers like Swift and Marzluff think that crows recognize dead individuals as signs of danger, and opportunities to learn about potential threats. In one study, they showed that crows become wary of places where dead crows are found, and will harass humans or hawks who handle the corpses. But if they treat dead individuals as signs of danger, why would they approach one, much less have sex with it?

To find out, Swift needed some dead crows. Fortunately, it’s not hard to get some in Seattle. When local rehabilitation facilities can’t save the birds in their care, they donate the bodies to the local natural-history museum. When private citizens find birds that have crashed into windows or collided with power lines, they do the same. Swift procured dozens of crows from the museum’s freezers, and her colleague Joel Williams stuffed them. Then Swift drove through Seattle and its neighboring cities looking for crow nests. When she found them, she would patiently wait for the owners to leave, before placing a dead bird on the sidewalk. “People often called the police,” she says. “They see someone with binoculars and a camera near their property.”

Over three consecutive summers, Swift tested the responses of hundreds of crows to their dead peers. Most often, she found that the birds made alarm calls from afar, or rapidly dive-bombed the bodies. This fits with the idea that they generally treat dead crows as signs of danger. But in 24 percent of the cases, something overwhelmed those instincts and the birds would touch, pull, drag, or peck at the corpses. And in 4 percent of the cases, these encounters turned sexual.

“In the most dramatic examples, a crow would approach the dead crow while alarm calling, copulate with it, be joined in the sexual frenzy by its presumed mate, and then rip it into absolute shreds,” Swift wrote. “I must have gone through a dozen dead crows over the course of the study, with some specimens only lasting through a single trial.”

These crows were not trying to scavenge from the remains. Cannibalism has rarely been reported in crows, and Swift found that the birds treated dead peers differently than the carcasses of other animals such as squirrels or pigeons. Nor were the crows simply mistaking the corpses for living intruders. Swift found that they treat crows that were taxidermied in lifelike postures differently from those preserved in deathly poses.

It also isn’t the case that crows are so desperate for a mate that they’ll copulate with anything. Sure, necrophilia was more common toward the start of the breeding season, but Swift found that the crows would mount dead birds even when their living mates were nearby. In one memorable instance, a pair of crows saw a dead body and then proceeded to mate with each other.

Swift suspects that during the breeding season, a minority of crows, whether due to inexperience or the cocktail of hormones in their brains, lose their ability to deal with unusual stimuli. A dead crow has some of the characteristics of food, an intruder, or a mate. Faced with several possible conflicting responses, the crows choose all of them. That’s why they display such an unusual blend of aggression and sexual advances. “It’s the result of them not quite processing all this information correctly and just responding with everything,” she says.

This is the first experimental study to measure the prevalence of necrophilia in a wild animal, but there are plenty of anecdotal accounts in other species. Bottlenose dolphins, humpback whales, ground squirrels, toads, and lizards have all been seen mating with dead individuals. Most (in)famously, the Dutch researcher Kees Moeliker documented a mallard mating with another dead mallard that had crashed into his window—an observation that earned him an Ig Nobel Prize, and was immortalized in an opera.

Sex aside, there are also many documented cases of animals grieving, which the anthropologist Barbara King defines as “some visible response to death that goes beyond curiosity or exploration, to include altered daily routines plus signs of emotional distress.” Elephants, dolphins, and chimpanzees have been noted standing watch over or carrying the bodies of dead babies and companions.

These behaviors have been long ignored because “for so long, the possibility that animals might be grieving or sharing some semblance of the human experience was laughable,” Swift says. “But it’s interesting to see this shift where this has become a legitimate scientific field. These cases help us develop a deeper experience of the natural world, and that’s never a bad thing. No one has ever walked away from that a worse person.”