Takeda Pharmaceutical Co.’s ambitions to expand in the lucrative U.S. health care market led the drugmaker to begin a painstaking examination of Shire PLC’s assets more than two years prior to striking a $62 billion deal.

In particular, Shire’s neuroscience unit and its gastrointestinal products sparked Takeda’s interest. One hurdle, though, gave them pause: the steep purchase price.

Then the tide turned in Takeda’s favor. Shire’s struggling stock performance after its failed sale to AbbVie Inc. and the acquisition spree that followed — culminating with the $32 billion takeover of Baxalta Inc. — frustrated investors and prompted concerns about its strategy. To appease them, Shire in August announced a potential spinoff of its neuroscience unit, potentially valued at $10 billion to $15 billion.

This account of how the takeover came together is based on conversations with people involved in the deal, all of whom asked not to be identified so that they could speak freely. Representatives for Osaka-based Takeda and Dublin-based Shire declined to comment.

After evaluating a purchase of the pricey neuroscience unit for a couple of months based on public information, Takeda executives last fall decided to aim higher — to acquire all of Shire. That would allow them to diversify their portfolio, avoiding future woes when patents expire.

So Takeda lined up bankers familiar with the company at Evercore Inc. and JPMorgan Chase & Co., along with Japan’s Nomura Holdings Inc.

To minimize leaks, executives assembled a small team with the goal of approaching Shire’s board by Easter, which this year fell on April 1. The people employed in the secret talks used code names based on Japanese whisky brands. Takeda was christened Yamazaki, the nation’s No. 1 single malt. Shire was coined Hibiki, described on its producer’s website as a seductive, enigmatic blend that evokes a sense of luxury.

And then the deal talks were almost upended. On March 28, a few days before the offer was to be made, rumors of it began to emerge, boosting Shire’s price and triggering a call from the U.K. takeover panel asking Takeda to confirm its intentions.

The drugmaker and its external advisers, some of whom were on vacation at the time of the leak, were shaken. They called Shire to formally apologize. The Japanese suitor had sought a friendly deal, with the goal of evading rival offers that could disrupt the talks.

The statement also caught Shire and its advisers at Goldman Sachs Group Inc., Citigroup Inc. and Morgan Stanley by surprise. Takeda shares plunged on concerns about the sheer size of the transaction and its rationale. Shire investors, meanwhile, began to anticipate that an offer would emerge from a larger drugmaker with deeper pockets — and at a higher premium.

In the following days, the financial hurdles multiplied as the gap in the two firms’ valuations widened.

The leak triggered frantic weeks of negotiations and meetings in New York — mostly at the law offices of Davis Polk & Wardwell LLP, a legal adviser to Shire — and by phone. The talks were led by Takeda Chief Executive Officer Christophe Weber and Shire Chairwoman Susan Kilsby, with Shire CEO Flemming Ornskov also playing a crucial role.

Strict takeover rules in the U.K. made it difficult for Takeda to explain its reasoning to investors, who worried that the target was too big to swallow without putting its debt rating at risk. Takeda’s market value is currently at $33.8 billion, while Shire’s is about $50.2 billion.

Still, Takeda didn’t run into much competition. With the exception of Allergan PLC’s short-lived exploration of a rival bid for Shire, no drugmaker stepped forward. That paved the way for Takeda’s transformation into a global powerhouse with a suite of rare-disease drugs.

Shire wasn’t won over easily, spurning four offers from the Japanese company. Ultimately, Weber and his team prevailed, acquiring the bank loans and backing of Shire’s board to seal the $62 billion deal, the biggest in Takeda’s history.

But there was no time for the traditional celebratory dinner that typically follows, as the two sides raced against the clock to complete the takeover by a May 8 deadline.

And though Takeda succeeded in its years-long quest, the drugmaker is left with a pile of debt and the task of combining two companies with different sizes, cultures and areas of focus in the drug industry. Integrating the Japanese drugmaker — which began by selling herbal therapies 237 years ago — with the sprawling Irish biotechnology behemoth may prove to be more complicated than sealing the deal for its purchase.