One fox learned the hard way that it's unwise to mess with a flock of dinosaurs.

The young fox, just about 6 months old, probably thought it had struck gold when it snuck into a chicken coop at dusk last week at a farm school in Brittany, in northwestern France.

But chickens, like all birds, are the descendants of dinosaurs. And this particular coop held 3,000 hens. As soon as the sun set and the light-controlled, automatic hatch door closed behind the fox, the birds channeled their inner Tyrannosaurus rex and attacked the fox. [Photos: Birds Evolved from Dinosaurs, Museum Exhibit Shows]

"There was a herd instinct, and they attacked him with their beaks," Pascal Daniel, head of farming at the agricultural school Le Gros Chêne ("The Big Oak"), told the AFP news agency. "It had blows to its neck, blows from beaks."

The following day, the school's students found the fox's dead body in a corner of the coop.

It's no secret among chicken farmers that these birds can be vicious. Chicken flocks have a clear hierarchy, sometimes referred to as the pecking order, with the biggest, strongest and most aggressive bird ruling the roost. As the "pecking order" name implies, these top birds bully their way to the top by intimidating and pecking weaker birds into submission, according to Modern Farmer, a news outlet for food producers and consumers.

Birds at the top of the hierarchy get better access to food, water and dust-bathing areas, as well as the best spots in the coop, Modern Farmer reported. But these boss birds also bear a special responsibility; they have to keep a constant lookout for predators and guide the other birds to safety if danger is near. In this case, the chickens didn't flee, but instead banded together to ambush the fox.

"They can be quite tenacious when they are in a pack," Daniel told the regional newspaper Ouest-France (translated from French).

Genetics may be the reason, in part, that some chickens lord over their fellow fowl (and, in this instance, a juvenile fox). According to a 2016 study in the journal Scientific Reports, Chinese scientists found a number of regions on the chicken genome that were associated with aggressive behavior traits.

However, chickens usually don't win the battle against larger predators. The last time a fox got inside the henhouse, more than a year ago, the encounter didn't end so well for the chickens, Daniel said.

Originally published on Live Science.