In the 1980s, scientists trying to save sea turtles noticed something truly bizarre.

They thought they were doing something good: rescuing eggs from vulnerable beaches and keeping them warm in incubators until they were ready to swim out to sea.

But when the sea turtles were born, almost every single one of them was male. At that point, scientists had known for some 80 years that sex was determined by a creature’s chromosomes. It seemed crazy that you could skew a hatchling’s gender just by taking its egg out of the sand — just as crazy as saying that the gender of a baby depended on where its mother lived while she was pregnant.

And yet here were dozens of all-male sea turtle siblings wriggling in front of them, emphatically suggesting that sex wasn’t as straightforward as it seemed.

What those scientists encountered was temperature-dependent sex determination (TSD), a phenomenon found in a range of cold-blooded animals. Unlike mammals, birds and other creatures, whose sex is set by the chromosomes they get from their parents, the trigger that causes turtle embryos to develop into baby boys or girls comes from outside the egg. Warmer ambient temperatures during incubation will make the hatchlings skew toward female. But keep the eggs just a few degrees cooler — as the scientists in the ’80s inadvertently did — and they’ll come out mostly male.

Five decades later, scientists are still trying to understand exactly how and why that happens. From an evolutionary standpoint, it seems like a pretty risky adaptation; it would only take a few hot years full of female hatchlings to spell the end of the entire species. And from a developmental standpoint, it’s just as confusing. If an embryonic turtle’s chromosomes aren’t telling it what way to grow, what is?

Turk Rhen, an integrative biologist at the University of North Dakota, has devoted much of his career to studying those questions. And he may have found an answer to at least one of them. In a study published in the journal Genetics this week, Rhen and his colleagues identify a gene that seems to be responsible for turning hot and cold temperatures into girl and boy babies.

If they’re right, the find could help keep turtles safe in an ever-warming world.

But, “like every scientific project ever,” joked co-author Kelsey Metzger, a former master’s student in Rhen’s lab and now a life sciences professor at the University of Minnesota at Rochester, “there’s a lot of work that came before it, and there’s going to be a lot of work that comes after it.”

What came before were decades of research into the sex differentiation of common snapping turtles — large, sturdy-shelled, sharp-beaked reptiles that inhabit ponds and streams from Florida to southern Canada and as far west as the Rocky Mountains. Rhen’s turtles come from Minnesota.

Even though the trigger for differentiation isn’t genetic, scientists know that the developmental process that turns a sexless embryo into a male or female turtle is more or less the same as in other species: It’s carried out by genes. Past research has shown that, early in development, some of the same genes that control sex in humans are also put to work in turtles. As each gets switched on, they cause amorphous blobs of tissue to differentiate into male and female reproductive parts, setting off a cascade of reactions that eventually produces a baby boy or girl.

But Rhen wanted to know where the whole process started. Those genes might control sex, but they don’t respond to temperature. Somewhere in the body, a thermometer gene must be telling them what to do.

He and colleague Anthony Schroeder, the lead author on the latest paper, first identified their candidate gene several years ago: the cold-inducible RNA-binding protein gene, or CIRBP (pronounced “surp”) for short. It’s known to be involved in body heat regulation in humans and other mammals, raising and lowering our temperatures according to the rhythms of our days. But it’s also something like the project manager on the construction site that is a developing embryo; it directs the transcription of DNA (the body’s molecular master plan) into RNA (its working blueprint), which then creates the proteins that do the body’s work.

In his newest study, Rhen tested to confirm that CIRBP was being turned on at the right time and in the right part of the embryo to be responsible for taking the temperature and directing the body’s response. Turtle eggs in incubators had their ambient temperatures changed by less than 10 degrees Fahrenheit during a five-day window of development when differentiation was known to take place. Then their tissue was examined to see how they responded.

The reaction was almost instantaneous.

“The gene expression changed within 24 hours of the shift,” Rhen said. Two days after that, the genes that scientists know are involved in sex differentiation started to spring into action.

Not only that but a minute variation in the gene — swapping out just one of the molecules that make up DNA for another — changes how turtles respond to temperature. One version lowers the temperature threshold for females — which are typically born at the warmest incubation temperatures. The other version raises it.

“We don’t know for sure yet,” Rhen said. “But our hypothesis is that CIRBP might be upstream and is involved in regulating expression of all those other genes” that determine sex.

Rhen also has a theory to explain why turtles evolved this way in the first place — one that, like his genetic explanation, is looking more and more convincing. In 1995, he and a colleague used hormones to get female turtles to hatch at “male” temperatures and found that the females grew incredibly large, far larger than they normally would be.

Paired with the knowledge that larger male turtles are usually more successful since they can fight off competition and hold down territory, a picture began to take shape: Natural selection favored male turtles born at lower temperatures because those temperatures speed up development and result in larger bodies. Those successful males then passed down their low-temperature favoring genes, and, over time, the current temperature regime took shape.

Which was all fine and dandy, until the planet’s temperatures began dramatically rising.

A recent report on loggerhead sea turtles in Florida found that the vast majority of nests studied produced between 90 and 100 percent female hatchlings four years in a row. Researchers studying painted turtles in Mississippi estimate that an average temperature increase of just 1.1 degrees Celsius would be enough to skew the population all female.

“It’s ultimately extinction,” ecologist Rory Telemeco, lead author of the painted turtle study, told the New Scientist in 2013.

Understanding the genetic mechanism will become more and more important as Earth warms, the researchers say. Knowing that some turtles have, say, the gene variant that raises the temperature threshold to skew female might help scientists to save them.

“There’s a lot of discussion going around with climate change,” Metzger said. “But in the end, the question is, is there enough genetic variation that these species will be able to adapt?”