Last summer Charlie Bancroft, chief financial officer of Bristol-Myers Squibb, got a wild idea: Bristol should ditch its diabetes business.

For years Bristol BMY had committed to the disease in a big way. It had spent close to 15 years developing two drugs for Type 2 diabetes — Onglyza and Forxiga. It had even teamed up with British rival AstraZeneca, a company that had a crack primary-care sales force, to help get them off the ground.

Then, in 2012, the partners deepened their commitment to diabetes, shelling out a pricey $7 billion for Amylin, the maker of two more promising meds. By 2013, Bristol’s five diabetes drugs were bringing in $1.6 billion in sales — not a huge amount, but enough to account for 10% of the company’s revenue. And with an expected FDA approval for Forxiga just months away, that share was almost sure to get a bump. All along, corporate messaging had been consistent: In annual reports, earnings calls, and press releases, Bristol touted diabetes as one of its most important medical focuses and a linchpin of the company’s future.

It was a worthy goal, certainly. With an estimated 26 million Americans and some 315 million people worldwide suffering from the Type 2 form of the disease — an often brutal, life-altering condition that typically requires arduous surveillance and daily treatment — the need for new and better medicines was great. And such numbers, it was lost on nobody, also made diabetes a bright red target for drugmakers — one that, according to information services firm IMS Health, was worth some $54 billion in 2013, and expected to grow by double digits through 2020.

This was what Bristol’s CFO was thinking of abandoning. Bancroft, a wiry, genial fellow whose 30-year career at Bristol had taken him from being the most junior finance guy at the company to the most senior one, knew it sounded nuts. “Most pharma businesses don’t get rid of pharma businesses,” he says.

When he told Lamberto Andreotti his idea, the Bristol CEO wasn’t enthusiastic. But Bancroft knew his boss well. They had worked closely together since the early 2000s, beginning not long after Andreotti, the son of an Italian Prime Minister, joined the company’s European oncology unit. “His no is never no,” says Bancroft. “It means you have to be much more convincing.”

By December, the convincing had come. Diabetes was a huge market, but a saturated one — requiring prodigious sales resources while delivering often-slight margins. The segment was the last vestige of “primary care” business at Bristol, which had staked its future on specialty drugs where both the risks and rewards were great. The company, in fact, had already struck gold on one medicine that, many were saying, would reinvent the way we fight cancer. Plus, says Andreotti, “the price was right.”

BMS.06.16.14 timeline

Click image to enlarge.

Bristol announced it was selling its global diabetes business to AstraZeneca for $2.7 billion, a sum that would rise to more than $4 billion after royalty and milestone payments were included. “We were a bit afraid of announcing it,” says Andreotti, Bristol’s CEO since 2010. “It was not fully kosher from a Big Pharma point of view. When I told my board the first time, they looked at me like …” He drops his jaw and makes a face like he’s just seen a yeti.

The market had a different reaction, sending the company’s shares up to a five-year high. By February of this year, when the ink on the deal had dried, Bristol officially became the tiniest it had been in years — with 18,000 fewer employees and roughly half the manufacturing facilities it had in 2007. On Wall Street, meanwhile, its value has surged to $82 billion, up an annualized 19.9% in the past three years, compared with a return of 14.4% for the Amex Pharmaceutical index.

It’s easy to miss the trend. At a moment when the world’s fourth-largest pharmaceutical company by sales (Pfizer) is eagerly courting the world’s ninth-largest (the very same AstraZeneca from which Bristol decoupled) — offering, in late May, a monumental dowry of around $120 billion — one can be forgiven for not noticing the more substantive change that’s sweeping the pharmaceutical industry: Big Pharma is getting smaller. On purpose.

Merck MRK shed its consumer health unit in May. Sanofi put its nearly $8 billion portfolio of mature drugs on the market in April. The month before, Baxter BAX announced it was splitting in two. Abbott ABT spun off AbbieVie ABBV . Even mighty Novartis, the No. 2 pharma company in the world after Johnson & Johnson JNJ , trimmed four divisions as it built up its cancer portfolio. Yes, the model that most major drug companies are hoping to emulate these days isn’t Pfizer (No. 51 on this year’s Fortune 500), but rather Bristol-Myers Squibb, No. 176 — which is down from No. 158 in 2013 and a rank of No. 134 the year before. Hey, with any luck, who knows? It could be even lower next year.

BMS.06.16.14 streamlining successA

Click image to enlarge.

The change had been a long time in the making — starting abruptly on a day in September 2006, when Jim Cornelius flew to New York City from his Indianapolis home for a meeting of Bristol’s board of directors.

Cornelius, a former Guidant CEO who joined the Bristol board in 2005, had not even packed an extra shirt for what he expected would be a routine trip. But the agenda that afternoon was full. Bristol had been operating under the supervision of a federal monitor — an arrangement that had been negotiated a year earlier with Chris Christie (then a U.S. Attorney for New Jersey) after the government had accused the company of accounting improprieties. Now the monitor was questioning negotiations that Bristol executives had with a Canadian company called Apotex, which was planning to launch a generic version of Bristol’s crown jewel: the blood thinner Plavix. Bristol management had offered to pay Apotex to delay the launch without sufficiently consulting the board — a fact that worried the federal monitor.

In the end the effort failed anyway. Apotex flooded the market with a six-month supply of generic blood thinner. Before a U.S. judge could stop the deluge, Bristol had lost at least $1.2 billion, according to its annual report.

The debacle cost CEO Peter Dolan his job. And in the wee morning hours of Sept. 12, Cornelius inherited one. What he’d actually gotten, though, was a mess.

In a conference room a few floors up from Cornelius’s rented apartment at New York’s Time Warner Center, the interim CEO laid out for Bristol’s senior management what he saw: “a mini J&J” that had been “stretched too thin” to truly excel at anything anymore. Early in the decade the company had been dogged by R&D failures, most notably of Vanlev, a high-profile hypertension drug that had been hailed as a can’t-miss blockbuster but then fell short of even getting FDA approval.

Once the titan of cancer drugs, Bristol had failed to develop a follow-up to Taxol, a hotshot cancer drug. Instead it allegedly schemed to block generics from competing with the drug, prompting lawsuits from all 50 states. (Bristol paid $135 million to settle the claims — plus an additional $535 million to settle similar allegations surrounding the anti-anxiety medication BuSpar.) Then there was its relationship with the infamous ImClone, a biotech firm that had developed what seemed to be a revolutionary colon cancer drug called Erbitux. Bristol invested heavily in the company — and soon found itself in the midst of a tabloid tizzy when ImClone’s CEO was sent to jail for insider trading (and craft queen Martha Stewart ended up in the hoosegow on a related matter).

Bristol-Myers Squibb
Bristol-Myers Squibb CEO Lamberto Andreotti (left) and Chairman Jim Cornelius — Photograph courtesy of Bristol-Myers Squibb 

Aside from the various scandals, patent protection for drugs that accounted for half of Bristol’s pharmaceutical revenue was nearing an end or otherwise in jeopardy. Rumors swirled that Cornelius had been brought in to sell the company to Sanofi, a French pharmaceutical company that collaborated with Bristol on Plavix. The hallways at Bristol’s Princeton, N.J., facility were filled with nervous chatter about employees “taking French lessons.”

“It was a very disconcerting time,” says Sandra Leung, who moved into the role of general counsel when Cornelius became CEO. “All of a sudden, we had a new CEO who no one was familiar with. And he was challenging us to think differently. People weren’t sure where it was going to lead.”

Neither was Cornelius. Everything was on the table. Over the course of the next year the CEO and his inner circle considered everything from making Bristol an R&D-only organization to moving the company to the Bay Area. The intense, full-day strategy sessions invariably ended with Cornelius getting a headache, he says — particularly when he sparred with executives in the company who clung to vestiges of big, fat pharma. He was unpleasantly surprised to discover much of Bristol management was unaware that the company was the least profitable in the industry.

By December 2007, Cornelius and Andreotti — who was chief operating officer at the time — had a plan. Bristol would grow … small.

The word had never exactly been in the company’s playbook. When Bristol-Myers and Squibb merged in 1989, they formed the world’s second-largest pharmaceutical company (and something more: Bristol-Myers brands included Drano, Windex, and Clairol). Both were health care giants with proud histories — Squibb had supplied medications to the Union Army during the Civil War and marketed the first electric toothbrush; Bristol-Myers provided penicillin to U.S. forces during World War II and briefly ran Palomar Pictures, the studio responsible for The Stepford Wives. Separately, and then together, Bristol-Myers and Squibb remain in a small club of companies to have been ranked on the Fortune 500 for the entire history of the list.

That was all about to change. Bristol quickly began to cut fat: Gone was the $18 million corporate aviation unit, with its two Gulfstream jets and a corps of Bristol pilots and mechanics. New York corporate staff moved to a lower, more modest floor in their Park Avenue office, and the enterprise began printing drug information sheets on lighter-weight paper. (The company was so proud of this last line item that it got a mention in the annual report.)

By 2012, the company had shaved $2.5 billion in costs, a third of its workforce, and all but 12 of the company’s 28 manufacturing facilities. Much of the trimming was done through the rapid sale of Bristol’s non-pharma assets — a medical imaging unit and ConvaTec, a wound care company — and the spinoff of Mead-Johnson, its high-performing infant-nutrition business. (Bristol also took a step back from emerging markets.)

Bristol Myers Yervoy Cancer Drug Jim Allison
Jim Allison’s discovery has helped keep more patients with metastatic melanoma alive. — Photograph by Nathan Lindstrom for Fortune 

At first the widespread feeling in the pharma industry was that the divestitures were foolish. Many said that Bristol, with its patent cliff looming, was cutting the strings of its parachute. In truth, the company’s top brass wasn’t interested in merely saving the company; they wanted a metamorphosis. They got one. Jami Rubin, an analyst with Goldman Sachs, says Bristol’s transformation is the most striking she has ever seen in the sector. “It’s really quite startling,” she says. “It’s a completely different company today than it was back in 2007. They’ve gone from a big, diversified drug company to a highly focused biopharma firm.”

While Bristol’s $16.4 billion in revenue in 2013 is down 7% from the year before, its profits (nearly $2.6 billion) are up an impressive 31%.

It wasn’t enough just to shrink. Bristol’s most noteworthy achievement, arguably, was that it had a keen sense of what to invest in: a handful of diseases where it could truly excel. “At the time we had more products in the pipeline than we had money to develop them,” says Cornelius, who retired as CEO in 2010, though he remains chairman. The aim was to select therapeutic areas where the market was not that crowded, where the opportunity for medical progress was substantial, and where it could find partners to share both the risk and reward. In addition to diabetes, it staked out medicines in key areas like virology (particularly HIV and hepatitis), immunology (Crohn’s disease and rheumatoid arthritis), and oncology. Cornelius called them Bristol’s “string of pearls.”

As it happens, the portfolio included one rare diamond too.

When he wasn’t playing harmonica for his Texas Honky Tonk Band, Jim Allison could generally be found with his mice. A native of Alice, Texas, Allison had somehow ended up in crunchy Northern California — at UC-Berkeley, no less — studying the immune systems of little white rodents. Hoping to learn something about how the human body defends itself against cancer, he had zeroed in on a complex regiment of lymphocytes called T cells, common to the immune systems in both mouse and man. As far as scientific questions went, Allison’s was pretty straightforward: What activated them? Who or what told these soldiers to go headlong into battle?

In 1987 a group of French scientists had discovered a protein protruding from the surface of T cells, which they called CTLA-4. Many biologists were convinced that this molecule was a go signal for T cells, sending the command to attack a pathogen or other invader. For a long time Allison, a gentle-spoken, scraggly-bearded fellow who is now chair of immunology at MD Anderson Cancer Center in Houston, had thought the same thing.

Then he discovered the opposite (as did another researcher at the University of Chicago). Rather than an activator of T cells, the molecule acted like a brake, stopping the immune system from its attack. The next question for Allison was whether he could somehow disengage the brake. Allison spent a year creating a mouse antibody that could block CTLA-4. When at last he succeeded, he injected it into mice that he’d implanted with tumors. The masses disappeared in nearly all of them. Allison was stunned. “That you could remove one thing,” he marvels, “and very often get a complete response and permanent immunity — that was just astounding.”

He published his findings in March 1996, but there was little interest. Allison spent the next couple of years pitching his work to biotechs and big pharmaceutical companies, hoping to find one that would develop an antibody that could block the same cellular target in people.

Bristol Myers
Bristol’s new site, in Devens, Mass., is used to produce biologics medicines, like one for rheumatoid arthritis. — Photograph courtesy of Bristol-Myers Squibb 

That scientific challenge was difficult enough. But even beyond that, says Allison, the very concept of immunotherapy was a hard sell. Ever since the turn of the 20th century, when an American physician named William Coley treated cancer patients with a mix of bacteria to provoke an immune response to their malignant disease, there has been excitement over the idea of harnessing the immune system to fight cancer (see timeline). Excitement, that is, followed by disappointment. In the 1970s researchers hoped a human immune substance called interferon would be cancer’s holy grail. (It wasn’t.) Then, in the 1990s, many thought as much of another natural protein, interleukin-2. Same ending.

In Allison’s case there was also frank disbelief that T cells even had built-in inhibitory signals, he says. It took another couple of years before Allison and two scientific colleagues entered a collaboration with a Princeton, N.J., company called Medarex. Nils Lonberg, a Harvard-trained molecular biologist who worked at Medarex, had figured out not only how to engineer a mouse with human immune genes but also how to make antibodies from these genes that were fully human as well.

Even so, the task was challenging. The men worked furiously for more than 15 months before they had an antibody that could put the reins on human CTLA-4. They called it ipilimumab. A decade later, in 2009, the drug — later marketed under the name Yervoy — would belong to Bristol-Myers Squibb. So, for that matter, would Medarex, the company that developed it.

Bristol’s $2.4 billion purchase of Medarex — which pharmaceutical analysts routinely cite as one of the best acquisitions in the history of the industry — would give the company not only a new blockbuster but also a leadership position in a burgeoning drug category: immuno-oncology.

Luck had something to do with it. But Bristol’s top management had helped manufacture that luck by recognizing — when many others didn’t — that Yervoy was a diamond in the rough.

In 2000, Medarex began its first phase of human testing on its new “CTLA-4-blockade” — in patients who had either prostate cancer or metastatic melanoma, a deadly form of skin cancer. If anything, though, the clinical trials provoked more questions (and even doubt) than answers. “The response pattern was a little bit funky,” says Francis Cuss, Bristol’s chief science officer. “People were getting benefits, but not according to conventional wisdom.”

When Jedd Wolchok, a cancer doctor and immunologist leading a Yervoy trial at Memorial Sloan Kettering, examined a melanoma patient’s scan 12 weeks after he’d received his course of treatment, the results were utterly disappointing — just like those of any other metastatic patient in the final throes of the disease: The tumors had gotten bigger, and there were more of them. “It looked for all the world as if the drug was failing,” says Wolchok. But before he could deliver the news, his patient stopped him: “Don’t tell me what the pictures show,” he said. “I first want to tell you I feel better.”

Wolchok wondered if the radiographic images lagged behind the drug’s progress, and he and his patient agreed not to do anything and to meet again in two months. When the patient returned, he was almost free of disease. He’s still alive today, more than eight years later, with no sign of recurrence.

The case was yet more evidence that both the clinical trial doctors and the drug’s developers would have to be more patient in assessing this new type of therapy. The immune system sometimes takes time to adjust, and so responses can lag behind those seen with traditional chemotherapy. The good news is, they also last much longer. While much is still being learned about why, it’s believed that the immune system, which has a memory component, can be “re-educated” to recognize cancer in an enduring way, in the same way it recalls its response to pathogens long ago, says Suzanne Topalian, director of the melanoma program at Johns Hopkins. Tumors may also appear to get bigger with immunotherapy, not necessarily because they’re growing but because they may be inflamed with active immune cells.

Others in the industry were less prepared to wait out results. Roughly a decade ago Pfizer PFE developed a drug based on an antibody that it, too, licensed from Medarex — but gave up on it, says Allison, when the drug didn’t immediately shrink tumors.

Ultimately, of course, what matters isn’t tumor shrinkage but patient survival. And Elliott Sigal, who held the role of Bristol’s chief science officer until retiring in 2013, can still feel the chill that ran up his spine when he first saw the survival, or “Kaplan-Meier,” curves with Yervoy. So can Lamberto Andreotti, who had spent most of his career working in oncology and who is widely seen within Bristol as being among the biggest supporters of the Medarex acquisition in 2009.

The curves chart the survival of participants in different arms of clinical studies (those getting a given treatment and those not) — and in metastatic melanoma they inevitably came together over time, representing a sad reality for patients and a disturbing truth about decades of drug development. Whether or not they’d received drugs, all but 10% to 15% died within 10 years.

With Yervoy, though, the graph was different: Between the curves was a small but significant gap, showing that more than 20% of those receiving the immunotherapy were surviving long-term. Too small a percentage for those diagnosed with this disease, surely — but a genuine advance nonetheless.

Approved by the FDA in 2011 for metastatic melanoma, Yervoy was the first drug to offer a survival benefit to patients with that disease. Like a growing number of specialty drugs (Gilead’s Sovaldi, Dendreon’s Provenge, Novartis’s Gleevec, and Bristol’s own Sprycel), Yervoy’s staggering price has drawn the ire of many. The drug, given over four injections, costs $120,000 in the U.S. Bristol defends Yervoy’s price tag, saying it reflects the survival benefit and the steep cost of the drug’s development.

And it doesn’t seem fazed by the controversy. While Yervoy brought in $960 million in sales in 2013 (an enormous figure for a two-year-old drug with a small patient population), the company currently has more than 35 ongoing clinical trials investigating another drug that disengages the immune system’s brakes: the much-awaited nivolumab, which was also from the Medarex portfolio.

Nivolumab hits a different target (called “PD-1”) than Yervoy, and appears to be more effective and better tolerated. Goldman’s Rubin predicts that it will be, at the very least, a $4.5 billion drug by 2020. It has shown promise in metastatic melanoma, renal, and lung cancers — the last of which represents a huge opportunity for pharmaceutical companies (160,000 Americans are expected to die from lung cancer this year, compared with 10,000 from melanoma).

Unsurprisingly, much of the industry, once so skeptical, has thrown itself into the development of immunotherapy medicines for cancer. There are now more than a half-dozen drugs in development around the PD-1 pathway alone, and a number of companies jostling to be the first to FDA approval. Overall, reports Citigroup drug analyst Andrew Baum, the market for immuno-oncology drugs could be worth $35 billion within a decade’s time. “We’re just scratching the surface as to how big an opportunity this will be,” adds Rubin. “It’s going to be a huge market.”

For now many analysts say it’s Bristol’s race to lose — though Merck, which may have an edge in getting a PD-1 drug on the market, is close behind. (The race, in fact, became that much tighter in April, when Bristol announced that it would not seek FDA approval for nivolumab until late this year.)

Here, some industry analysts wonder if Bristol’s ever-shrinking size may ultimately be a handicap. In immuno-oncology — what might seem a classic “biotech-y” niche in Big Pharma — Bristol might actually need some heft to be a market leader.

In the company’s first-quarter earnings call in late April, an analyst asked whether Bristol had the commercial scale to compete effectively in immuno-oncology — particularly in light of a potential Pfizer-AstraZeneca merger. Andreotti, who by all accounts is inveterately affable, hardened — as if insulted by the suggestion that the company could not keep up.

“Yes, we are ready, and we are ready in the U.S., and we are ready all around the world,” he said sharply. “So nothing more to add there.”

No question about it, the smallest of the major American drug companies aims to punch above its weight.

This story is from the June 16, 2014 issue of  Fortune.