Karen Wille saw her panda friend for the last time in July 2016. He was in bad shape. He was skinny. His once-sleek black-and-white fur had dulled. Wille, a board member and volunteer with the nonprofit Pandas International, knew better than to expect wildlife-calendar perfection, airbrushed and coiffed. Even the most charismatic of megafauna have off days. Behind the big eyes and rounded frames that signal vulnerability and cuddliness to the human brain, pandas are real, live, 200-pound bears. Bears that can shred your flesh. Bears that roll around in the dirt and turn themselves dingy gray. Bears that grow old and frail.

But it was still hard to see reality catching up to her friend. Wille had been to China to visit this specific bear many times before. This time, though, nobody wanted to talk much about how he was doing. His keepers were more protective than normal. Wille had about five minutes with him — enough time for a pat on the head and a carrot. She was heartbroken, but not surprised, when he died five months later.

His name was Pan Pan. It translates to something like “hope,” an identity that likely meant one thing when he was an abandoned, sick cub on a Chinese mountainside and something very different later in his life.

When he died from cancer on Dec. 28, 2016, the 31-year-old Pan Pan was the world’s panda paterfamilias: the oldest known living male and the panda (male or female) with the most genetic contribution to the species’ captive population. Today, there are 520 pandas living in research centers and zoos, mostly in China. Chinese officials say more than 130 of them are descendants of Pan Pan.

Pan Pan saved his species by being really, really, ridiculously good at sex. Before Pan Pan, experts thought that building up a stable population of captive pandas was going to require extensive use of artificial insemination. Pan Pan not only led the way on reproducing in captivity, he taught us that pandas were perfectly capable of doing it for themselves — and they’re now increasingly allowed to do so. Scientists say giant pandas represent, hands down, the most successful captive animal breeding program humans have ever embarked on, and, partly, we have Pan Pan to thank. He was a big, fluffy stud muffin, and he was beloved. “It sounds kind of weird,” Wille said of their first meeting in 2012. “Most people want to meet rock stars or movie stars. I wanted to meet Pan Pan. He was a legend.”

From the edge of extinction, Pan Pan (and pandas) emerged triumphant. And their success is also ours — proof that maybe humans really can clean up the ecological messes that we make. In September 2016, the International Union for Conservation of Nature declared pandas to no longer be endangered. The animal whose image literally represents the fight against extinction is now merely “vulnerable.” Humans can ride off into the sunset with our heads held high.

At least, that’s one way to tell the story. But just as living bears are messier than their plush, gift-shop counterparts, the reality of conservation science is more complicated and nuanced than a poster or a press conference can convey. Pan Pan’s story is about human triumph — and it’s also about our limitations. Even the most well-intentioned plans have unpredictable consequences. And we can never truly erase a legacy of harm. Instead, we point a species in a new direction, we cross our fingers, and we hope.

In 1983, bamboo stalks across south-central China’s Baoxing County all went to seed at the same time, and panda experts panicked. While bamboo forests appear densely packed with plants, those represent the cloned offshoots of a mere handful of individuals, each of which will live to be only about 60 years old. Near the end of its life, the bamboo plant (and its hundreds of thousands of copies) makes one attempt at sexual reproduction. Heavy masses of seeds grow from the stalks, bending them over like wheat ready for harvest. The seeds scatter and the plants — all of them, for miles around — die.

When that happens, it’s bad news for panda bears. Even though pandas have the guts and stomachs of carnivores, their diets are almost exclusively made up of bamboo. After a mass bamboo die-off, it can take 10 to 20 years before the forest is fully re-established. That means years of famine for pandas — years of eating bugs and grass, years of intestinal problems and hunger, years of sickness and death. This cycle is natural, but human activities have made it harder. By the late 20th century, farms, roads and the logging industry had hemmed the bears in, making it difficult for them to simply lumber along to a place where bamboo was still plentiful. Habitat loss, in fact, was the primary issue forcing pandas to the brink of extinction. When the United States formally listed the panda as an endangered species in 1984, the Federal Register noted that the entire panda species — 1,000 individuals — was living on 11,000 square miles of land. Just four years later, China’s Second National Giant Panda Survey would show this estimate to have been incorrect. Instead, those 1,000 pandas had been living on just 5,000 square miles.

To protect the pandas, Chinese officials implemented emergency measures: refugee camps for starving pandas, food drops where workers left piles of cooked pork chops in the forest, a baby lift operation that scooped up young pandas and deposited them in zoos and research centers where nothing could come between them and a regular dinner bell. And this is how Pan Pan came into our world. It’s not clear who found him, but he soon ended up in the home of a man named Li Wuke, who was already caring for another baby panda called An An.

This part of Pan Pan’s story isn’t well-documented, and what bits of it have been passed down, largely through Chinese media, make the situation sound like a cross between a shoestring animal rescue operation and the elevator pitch for an animated musical. Li Wuke was an old man who lived in a tiny house in the mountains. He fed the two cubs, scolded them when they were naughty and slept between them at night in one narrow bed.

Pan Pan was a lovable plush mascot in the making — but he was also starting a life as a scientific research subject. Conservation isn’t usually described as an experiment, but in many ways, that’s exactly what it is. The Chinese government had been working hard to keep pandas safe since 1946, when it banned panda export and hunting by foreigners. But in the 1980s, the combination of a very real threat of extinction and advancements in reproductive technology turned attention to captive breeding. A healthy, self-sustaining population of captive pandas could be a safety net — assurance that the species would survive even if humans destroyed its habitat. That population could even be used to repopulate the wild, healing the damage humans caused. But nobody knew exactly how to do all of that.

On April 7, 1986, Pan Pan was given his first entry in the Giant Panda Studbook — a thing that really does exist — as Panda No. 308. The book is the definitive database cataloging the biographical details of every panda that has ever lived in captivity. It describes Pan Pan as a wild male, likely born the previous year and captured in Baoxing. And while the news reports suggest that Pan Pan’s idyllic childhood frolicking around the feet of Li Wuke lasted just one year, his entry in the studbook shows five unaccounted-for years in captivity in Baoxing, a gap that would take him to sexual maturity. On March 4, 1991, he was transferred to the panda breeding center at the Wolong Nature Reserve in Sichuan province. Wherever he was during the intervening years, reaching breeding age meant that Pan Pan, the beloved orphan, was now No. 308, the potential sire.

Pandas are not the only species whose lives are recorded in the staccato of a studbook — name, date, serial number. You can find similar books for elephants, gorillas, golden tamarins — basically any animal whose existence has ever been seriously threatened enough that humans want to make sure that it has lots of babies, and that those babies are genetically different enough from one another that they could keep the species alive without inbreeding. These documents are the checkbooks for living, breathing biological bank accounts. And they help scientists decide how to invest those savings in the form of breeding plans: which animals will mate, when they will mate, and how many babies need to be made each year.

But initially, there weren’t many panda births to record. At the time of Pan Pan’s first entry in the studbook, far more captive pandas had been brought in from the wild than born under human care, a fact that would remain true for another decade. In fact, between 1936 and 1998, only 12 males and 21 females reproduced in captivity at all. And of the captive cubs that were born from 1963 to 1998, 48 percent died within their first month of life. Few baby pandas lived past age 3.

It’s not abnormal to initially struggle to get a wild species to breed in captivity, but pandas proved to be particularly resistant. Some of that has to do with biology. Both males and females live solitary lives in the wild, coming together to breed once a year, during the two or three days when the females are fertile. If this works, and a baby (or two) is born, it will stay with its mother for as long as three years.

This naturally slow process had a reputation for getting even more bogged down behind bars. When Pan Pan arrived at Wolong, the thing captive panda mating pairs were best at producing was awkward moments. Sometimes, males wouldn’t appear interested in sex, as though they’d stumbled into a boudoir when they were looking for the kitchen. Other times, they’d just sort of dry-hump, like teenagers in the back of a Chevy. Worst of all were the times when either the male or female would get aggressive, lashing out violently at their would-be partner.

This is panda reproduction as most of us are probably familiar with it: bumbling, sometimes brutish and massively unproductive. Then came Pan Pan, the Dean Koontz to the other male pandas’ J.D. Salinger. Just six months after Pan Pan arrived at Wolong, his first child was born, a daughter called Bai Yun, who now lives in the San Diego Zoo. That’s remarkably quick work given that a panda gestation period lasts three to five months. Papa was a rolling stone.

By 1999, Pan Pan was the primary male breeding at Wolong, said David Wildt, head of the Smithsonian Conservation Biology Institute’s Center for Species Survival. In 2004, Pan Pan was featured in a research paper that quantified behavioral differences in mating success. The conclusion: He (and a couple of other particularly successful males) were just generally more interested in sex — and male interest in sex was a major factor in whether mating occurred. The paper noted that Pan Pan stood out for his especially long copulation time, upwards of seven minutes on average. “We have seen Pan Pan dragged by females around the entire circumference of the enclosure with no interruption of coitus,” the paper noted.

By 2006, Pan Pan was the parent of more than 30 cubs. No other panda, male or female, even came close. Meanwhile, the number of baby pandas born each year began to skyrocket. In 1991, the year Pan Pan’s first child was born, there were eight new captive panda cubs worldwide, according to the studbook. In the year 2000, 20 were born. Today, it’s not uncommon to get twice that number of panda babies in a year. By early October, the 2017 crop had reached 63. Pandas are now in such good shape as a species that scientists at Wolong have begun a program to return them to the wild. Pan Pan has become known as the “Hero Father.”

This might be the point where Pan Pan’s story starts to sound weirdly familiar, at least to those of you who’ve spent much time reading the Old Testament or the Koran. Lost boy found in the tall grasses? Taken in by a kindly stranger and raised as a prince? He becomes a great leader of his people, but — just as they reach the promised land that he has helped them to find — he dies. The metaphor fits together kind of eerily well. Except for one awkward bit. If Pan Pan is Moses, then we, humanity, are left playing the part of Egypt.

If the details of Pan Pan’s life document humans’ success as conservators, those details also document the complexity of what “success” really means. Again, conservation is an experiment. When we take an animal to the brink of extinction and back, that isn’t the same as returning to a pristine past. There are side effects that can’t be avoided. There are debts that can’t easily be repaid. Saving a species from ourselves is messy — and we aren’t always the heroes of that story.

For instance, the bears have often been framed as their own worst enemies — reluctant to mate, slow to reproduce. Faced with the most primal of animal urges, these particular animals do not feel especially urgent. But that stereotype is built on human error — and the mistakes we made in our early, clumsy attempts at matchmaking.

We wanted pandas to have sex on our terms, as research subjects. We expected them to mate in public, with whatever partners we chose for them, no real chance to get accustomed to each other and little knowledge of how adult pandas negotiate sex. “But … listen here,” said Meghan Martin-Wintle, executive director of the captive-breeding research nonprofit PDXWildlife and a postdoctoral researcher at the San Diego Zoo Global Institute for Conservation Research. “Animals choose partners based on a variety of reasons. As humans, we don’t even understand what those reasons are.”

And, when the pandas predictably rebelled against this experience, humans turned to artificial insemination — a process that amounted to minor outpatient surgery. During artificial insemination, male pandas have to be anesthetized and then stimulated into ejaculating with the help of an electric probe placed in their rectums. Female pandas also have to be sedated during the actual insemination. Some bears went through this process several times during their fertile period every year, said Kati Loeffler, a veterinary adviser to the International Fund for Animal Welfare and former director of animal health at the Chengdu Research Base of Giant Panda Breeding in western China. Loeffler has since become a fierce critic of animal welfare practices within the panda breeding program.

But it wasn’t artificial insemination that led to the panda baby boom. Instead, that success was the result of a slow realization that pandas did better breeding on their own terms, as bears. Today, Wolong and its network of breeding centers favor the natural mating strategies that made Pan Pan famous, said Martin-Wintle and other researchers. There, pandas are given opportunities to mate with multiple partners. Young males get to see other adults mating. When it’s their first time, they’re paired with experienced females. Even when females are both inseminated and allowed to mate naturally, the father usually turns out to be one of the natural mates, said Kathy Traylor-Holzer, senior program officer of the International Union for Conservation of Nature’s Conservation Planning Specialist Group. Meanwhile, the zoos still most dependent on artificial insemination are places that only have two adult pandas who just aren’t that into each other.

We set out to help pandas reproduce but ended up creating a problem that hadn’t previously existed — and which we then had to figure out how to solve. And that’s a theme that turns up over and over in this entire 40-year, multi-generational experiment. Consider all those fluffy baby pandas. Their numbers have meant that, over the past five or six years, the focus of the panda breeding program has been able to shift from simply making as many pandas as possible to making sure the pandas that are born are genetically diverse enough to carry the species forward for hundreds of years. There are now enough baby pandas that, in November 2016, the Chinese government began to seriously discuss maintaining the captive population at current levels, rather than continuing to increase it, Traylor-Holzer told me. That’s a major success.

But it comes at a price — hundreds of pandas living in perpetual captivity. Whether that is inherently a problem is a philosophical question, more than a scientific one. But it is easy to lose sight of the fact that none of the roly-poly cuddle balls you’ve seen in online videos or on display at zoos will ever make the journey back to the forest. Instead, they, like Pan Pan, will grow old and die in our care — a coming boom in panda geriatrics presaged by the existence of Dujiangyan, a panda research center near the central Chinese city of Chengdu that has a program focused on the needs of elderly bears and where Pan Pan spent his final years.

Wolong has a wild release program, but it’s still small and very few animals are released each year. For example, according to the 2016 panda breeding report, published in November 2015, there were 423 pandas in captivity — and two of them were scheduled for release. The next year, there were none scheduled for release. That’s partly because evolution is still at work, even within the walls of a breeding center or the cages at a zoo. When wild creatures are born and raised in captivity over several generations, we tend to train them for it and give special attention to the ones that get on best with us, said Nate Flesness, science director emeritus of Species360, an international nonprofit that manages studbooks for thousands of zoos and aquariums. We domesticate them, like cows, even if we don’t mean to. In captivity, you want animals that aren’t stressed out by the presence of people, that will submit to mating, or a medical examination, and that won’t attack somebody who comes to feed them. Pan Pan was one of those bears. And when we breed animals like that a lot, we’re selecting for tameness, Flessness said.

But it’s not at all clear that the traits that made Pan Pan good at adjusting to captivity and performing sexually in a cage would make his descendants good at returning to the wild he came from. For instance, Bai Yun, his first child, who now lives in San Diego, is herself a prolific breeder. She’s the mother of six of the 16 surviving cubs born in the U.S. And she is also known for being particularly congenial to humans — lying still for ultrasounds and urinating on command. In contrast, the animals that leave Wolong and return to the wild are basically raised in the opposite way as Pan Pan. Newborn bears are left with their mothers in giant, semi-wild enclosures — a patch of forest with a fence around it. Human contact is kept to an absolute minimum. There have even been breeding pairs selected with wild release in mind, Traylor-Holzer told me. Big, beautiful, independent bear, seeking same. Must not love humans.

There are downsides to letting one bear romance his way through the population, and Pan Pan’s outsized genetic contributions eventually came to be seen as more of a bug than a feature. Late in his life, Chinese scientists began choosing panda breeding pairs in ways that reduced Pan Pan’s long shadow. In 2006, about 12 percent of the total captive panda gene pool descended from Pan Pan. By 2016, this was down to less than 9 percent.

Nor has that breeding program — successful though it is — fixed the problems that put Pan Pan and his compatriots at risk to begin with: habitat reduction and threats from humans. This fact highlights how hard it can be to decide which side of conservation — captive breeding vs. wild protection — should get the most resources.

It’s not that we’ve ignored wild pandas. China has made some big strides, establishing 67 panda reserves by 2013. These national parks place limits on what humans can do and where they can go, and they’re credited with a big part of increasing the wild population. The Fourth National Giant Panda Survey, published in 2015, found 1,864 pandas living on more than 10,000 square miles.

But pandas’ inability to travel from one place to another is still a big problem, said Colby Loucks, senior director of the World Wildlife Fund’s wildlife conservation program. The panda reserves cover 58 percent of the pandas’ range, but both the reserves, and the panda population in general, are isolated from one another. A paper published in September 2017 found that while patches of habitat available for pandas have increased in number, the average size of those patches is 13 percent smaller than it was in 1988. The forest where pandas live is thinning like mangy fur.

Remember that this problem — and its effect on the pandas’ ability to respond to a food shortage — is exactly why Pan Pan had to be rescued in 1986. But habitat disconnection can also lead to genetic trouble. That’s because isolated bears are inbred bears. You don’t want any single family to have too big a role in a population. Just as we didn’t want Pan Pan contributing too much to the small population of captive pandas, we don’t want wild panda groups to become isolated from one another for too long.

That’s especially dangerous for the smallest population groups, Loucks said. And, when it happens, humans have to choose: Let a wild population of endangered creatures slip away, or go to comically elaborate lengths to solve an immediate crisis while not changing the system that created it.

The latter happened in Florida, where human development cut off a population of panthers from related big cats in the rest of the country. Those panthers became inbred enough that individuals were starting to display physical problems such as abnormal sperm counts and kinked tails. In 1995, researchers had to airlift in some genetic diversity, in the form of eight female cougars who were captured in Texas and woke from a tranquilizer nap to find themselves the mail-order brides of a wildly different ecosystem. Stories like this are a stark reminder that, despite captive pandas’ high rates of genetic diversity, the wild population could easily continue to grow in numbers while drifting toward genetic similarity.

Captive breeding can’t fix that. These are the kind of problems that Steven Beissinger, professor of conservation biology at the University of California, Berkeley, wrote about in 1996 in a highly cited paper on the limitations of captive breeding. Many of the problems he and his co-authors identified then still exist. Not only does captive breeding involve selecting individuals for traits that might not be useful in the wild (think about Pan Pan and his human-friendly offspring), but, without enough emphasis on habitat conservation, you could end up reaching the goal of wild release — only to send those carefully bred animals back to the same problems that that put their species in danger to begin with.

Some of the greatest success stories of conservation science are tinged with this irony. Take the California condor, a species that was down to 22 individuals in 1982 before scientists began breeding them in captivity and releasing them to the wild. At the end of 2016, there were 276 of them flying free. But that kind of resuscitation is not exactly the same thing as healing the patient. We bred condors and released them back into the wild, sure. But we never banned the lead shot that turned what the condors eat — animal carcasses — into deadly poison.

Today, Beissinger says, every “wild” condor is tracked by radio collar, regularly recaptured and tested for its lead levels. We feed them, too — a delivery service of lead-free dead cows. Our efforts straddle the line between ensuring the species survives and ensuring it can fend for itself like a truly wild thing.

And the number of species that could end up in this kind of situation is growing. There isn’t really a coordinated, global effort to monitor biodiversity on Earth and, as a result, it’s difficult to definitively say whether there are more species in need of rescue today than, say, 40 or 50 years ago. But increased efforts to understand and prevent extinction during that time period have meant more species documented, counted and officially recognized as being at risk. And thus, there are more species we have to sit down and figure out how to save.

Captive breeding will — and should — play a role in that. But, Beissinger said, there’s going to be a great temptation to rely on it too much instead of crafting a balance. It just seems so much easier than forcing humans to change their behavior — politically, socially, philosophically. It gives us the ability to feel like we really can clean up the ecological messes we make. “But it’s easier to load the ark than unload it,” he told me.

The other side of Pan Pan’s legacy is this: Once you break a species, you can’t easily put it back together again. The cracks will still show. Conservation is important, but it doesn’t undo the past. It can only help a species move forward, toward a future we don’t totally understand. From the moment Pan Pan was carried off that mountain and into the arms of a kindly old man, he could never go home again.

During the last couple of years of his life, when he was housed in an enclosure with a tree-filled yard at Dujiangyan, Pan Pan lived next door to one of his grandsons. That bear’s name is Tai Shan. He was born in 2005, a product of artificial insemination, the first baby panda to survive infancy at the Smithsonian National Zoo in Washington. Like all pandas born in the U.S., Tai Shan is the property of the Chinese government, not the zoo of his birth. In 2010, he was sent to the mother country, trading life as an American celebrity known in the press as “Butterstick” for a more anonymous routine as another captive panda who might, someday, become a parent.

Karen Wille used to go to visit Pan Pan and Tai Shan together and watch them watch each other through a window between their enclosures. On one side of the wall, there was the pandas’ past — a bear saved from the brink of death, a species rescued from extinction. On the other, the possible future of pandakind — safe, well-fed, semi-domesticated. Wille liked to think the two bears had some kind of connection, that they were drawn to each other. It’s a theory that would sound silly if it weren’t for the fact that research suggests it’s not totally out of the question. Turns out, the scents pandas leave on trees and walls are unique enough that you can identify individuals by their chemical profile.

Two not-so-wild animals, linked by genetics and fate, their existence in that place both a reminder of how successful panda conservation has been and how much further we still have to go. It’s not a huge stretch to imagine that maybe, just maybe, there was something Pan Pan and Tai Shan found familiar as they leaned their big, fluffy bodies against the concrete separating them from each other. Even if they didn’t know what it was.

Special thanks to Henry Nicholls, who provided me with a 2006 version of the panda studbook data and whose book “The Way of the Panda” is an excellent source for anyone who wants to know more about the science and politics of panda breeding. And to Ronald Swaisgood, Brown Endowed director of recovery ecology at the San Diego Zoo, who provided me with the 2013 version of the studbook data. Without these sources, I would have never “met” Pan Pan.

CORRECTION (Nov. 28, 2017, 1 p.m.): An earlier version of this article misstated the name of the organization that employs Colby Loucks. It is the World Wildlife Fund, not the World Wildlife Federation.