A little over two years ago, William A. Ackman, one of Wall Street’s brashest and most self-assured hedge fund managers, was on top of the world. A billionaire before he hit 50, he was generating double-digit gains for his investors and raking in hundreds of millions in fees for his firm and himself.

Hailed as a master investor, he clinched his highflier status in the fall of 2014 by paying $90 million with some friends to buy the penthouse at One57, a 13,500-square-foot aerie in Midtown Manhattan overlooking Central Park. He didn’t plan to live there — it was an investment property — but until he sold it, the apartment would make a good party space, he told The New York Times.

If Mr. Ackman were a stock, that might have been his peak.

Today, things are very different for him. His company’s performance is way down, he is in the midst of an expensive divorce, and on March 13, he and investors in funds run by Pershing Square Capital Management swallowed a $4 billion loss on Valeant Pharmaceuticals International, a beleaguered drug company.

As bad bets go, it was one for the record books. Valeant was a big Pershing Square holding. In May 2015, Mr. Ackman said Valeant’s acquisition strategy made it “a very early-stage Berkshire,” referring to Berkshire Hathaway, Warren E. Buffett’s investment vehicle. But only a few months later, Mr. Ackman and his investors began riding Valeant’s shares all the way from $262 to $11, driven both by rival investors who had bet against Valeant’s shares and former fans who dumped the stock as bad news emerged.

As much as Mr. Ackman and investors in his $11 billion firm would like to close the book on Valeant, they cannot do so quite yet. That’s because of a Valeant-related lawsuit in a federal court in California contending that he and his firm violated securities laws in 2014. According to the plaintiffs, Pershing Square secretly acquired a stake in the pharmaceutical giant Allergan based on nonpublic information from Valeant that it intended to mount a takeover bid.

This is not just any lawsuit. Damages in the case may be $2 billion, as noted by the judge who certified the litigation as a class action Wednesday. Mr. Ackman’s lawyers, who in court hearings have put potential damages at less than $1 billion, are vigorously contesting the case.

Defendants in the matter, which has not received a lot of publicity recently, are Mr. Ackman, his funds, Valeant and J. Michael Pearson, the company’s former chief executive.

The case is entering a crucial stage. Court documents indicate that Mr. Ackman and Mr. Pearson have either been deposed by lawyers for the plaintiffs or will be questioned under oath soon. The documents also show that Mr. Ackman must set aside 12 hours to answer questions.

Mr. Pearson was the architect of Valeant’s business model, in which the company acquired drugmakers and jacked up prices on their products. Mr. Ackman, 50, is one of the country’s best-known activist investors — taking large positions in companies and trying to use that weight to influence their direction and decision-making. Initially, Mr. Ackman praised Mr. Pearson’s strategy of acquiring rivals rather than developing drugs internally.

Mr. Ackman declined to comment on the mistakes he made in Valeant or the lessons he gleaned from the loss.

In a statement, Pershing Square noted that the firm “has generated billions of dollars of profits for its investors and double the stock market returns since the inception of the firm inclusive of our large loss on Valeant.”

“Unfortunately,” it continued, “we cannot guarantee that every one of our investments will be successful. We regret the loss which occurred due to Valeant board and management decisions made prior to our active engagement with the company. Over the past year, as members of the new board of directors, we have taken important steps to stabilize the company, including replacing prior management, which positions the company for a better and more profitable future.”

Due Diligence Falters

The stock market is a humbling place, where even astute investors make many mistakes. Mr. Ackman is by no means the only money manager to have erred in assessing a company’s prospects.

But as loosely regulated hedge funds have grown both in number and in power recently, a cult of personality has arisen. Unlike mutual funds, which employ ranks of portfolio managers, hedge funds like Pershing Square are dominated by the people who run them. Investors in Mr. Ackman’s firm are essentially placing a bet on him, his acumen and his discipline.

Some investment managers — Mr. Ackman’s peers and rivals — say that his Valeant wager raises questions about his investment style. His failure to limit his losses on the trade and his unusual public comments as a Valeant director, in which he cheered the company’s management and strategies even as its business was collapsing, are viewed as troubling.

D. Ellen Shuman is the veteran manager of Edgehill Endowment Partners, which oversees $650 million in nonprofit money. She evaluates money managers for her clients and said she had avoided investing in Pershing Square.

Why? “It is all about Bill Ackman,” she said in a recent telephone interview. “It is not about his investors or the companies in which he is investing.”

As confident a money manager as ever walked Wall Street, Mr. Ackman has acknowledged that his investment in Valeant represented a breakdown in his firm’s due diligence — the research it does about the companies it backs. That concession came last spring when he was called to testify before a Senate committee on Valeant’s drug pricing practices.

In an email to The New York Times, Pershing Square said, “Valeant is an anomaly in an outstanding record over nearly 14 years.”

But while his funds notched an exceptional 40 percent gain in 2014 — much of it attributable to the Allergan trade that has drawn the lawsuit — Mr. Ackman’s funds lost 13.5 percent last year and 20.5 percent in 2015. Through March 15, Pershing Square is flat.

Other hedge funds have turned in poor performances as well in recent years. And it is not clear whether or to what extent Mr. Ackman’s investors have reacted to his firm’s losses by fleeing. Pershing Square declined to disclose redemption figures.

As is typical with hedge funds, Pershing Square has rules governing client redemptions. In many cases, clients can withdraw only 12.5 percent every quarter over two years; this prevents a run on the operation amid a mass of redemptions. And several years ago, Mr. Ackman astutely raised permanent capital with a stock offering in Europe, another cushion against a run on the firm.

Still, his Valeant flop naturally brings to mind some of his previous high-profile mistakes. These include investments in the retailers Target and J. C. Penney, where he installed a chief executive who quickly crashed. And his protracted $1 billion crusade against Herbalife, a maker of health supplements, has lost money for his investors.

Finally, there’s his previous hedge fund, Gotham Partners, which ran into trouble when clients redeemed and its illiquid investments could not be sold quickly. He wound down that firm in 2003, and founded Pershing Square later that year.

$4 Billion Loss

One reason so many on Wall Street have been riveted by Mr. Ackman’s wrong-way Valeant bet is that it seems to confirm an age-old investing truth: Karma has everyone’s address.

For example, Mr. Ackman’s $4 billion loss in Valeant more than wiped out the $2.2 billion he made in 2014 on Allergan.

Interactive Feature | Valeant’s Rise, and Fall

Mr. Ackman had never invested in the pharmaceutical industry when he put over $3 billion into Allergan. Pershing had avoided such companies, Mr. Ackman told investors in April 2014, because they don’t generate predictable cash flows. Pershing preferred companies like Burger King and Kraft, whose strong brands protected them from competitors.

After generating a quick $2.2 billion profit in Allergan, Mr. Ackman continued his new interest in pharma. In March 2015, Pershing began putting about $4 billion into Valeant.

Initially, Mr. Ackman swooned over the company. At an investing conference in May 2015, he said, “We spent a year working with Valeant trying to take over Allergan, and one of the frustrations we had, as we got to see Valeant trading at $110 a share, was that we couldn’t buy the stock.”

He added: “But the moment we could, we bought it. You could say we’re late to the party.”

Mr. Ackman was more correct than he knew about coming late to his big Valeant purchase. His average cost was $190 per share.

At first, the investment scored. On July 23, 2015, Valeant reported blowout financial results; by early August, the stock had topped $262 a share.

Although few suspected it, that was the zenith for Valeant. By September the stock had fallen to around $160.

In October came a report from Citron Research, by the short-seller Andrew Left. Its headline: “Valeant — Could This Be the Pharmaceutical Enron?” The report delved into Valeant’s association with a shadowy specialty pharmacy operation known as Philidor. Valeant shares skidded to $110 on the news.

On Oct. 30, Mr. Ackman battled back with a four-hour conference call defending Valeant. The company was sound, he said, and although its stock would recover slowly, he expected it to hit $400 within three years.

Investors weren’t convinced; the stock closed down 16 percent that day.

“We held the call to respond to a large number of investor questions we received,” Pershing Square said in an email last week to The Times. “We presented our point of view and analysis based on the facts that we had at the time. We continued to hold the stock at that time because we believed there continued to be substantial upside on our investment.”

From then on, Valeant was essentially in free fall. In late December 2015, Mr. Pearson took a medical leave. In March 2016, Mr. Ackman joined Valeant’s board and the company announced it would replace Mr. Pearson. Hauled before congressional hearings about escalating drug prices in April, Mr. Ackman apologized for Valeant’s mistakes, vowing to use his position on the board to change the company.

As Valeant’s business flagged, investors began focusing on its $30 billion debt, taken on to acquire companies. Clearly the company was going to have to sell assets to pay it down, but as analysts noted, Valeant had typically overpaid for acquisitions; selling those units might not generate gains.

Mr. Ackman continued to defend Valeant publicly, an unusual stance for a corporate director. In May 2016, after Charlie Munger, Berkshire Hathaway’s vice chairman, criticized Valeant’s business model and called the company “a sewer,” Mr. Ackman took to CNBC. And in July of that year, he told an interviewer that Valeant’s phone was ringing off the hook because so many companies wanted to buy the assets it was selling.

By this time, the stock had drifted down into the $20s. The company’s business was faltering, and it was under investigation by regulators and the Justice Department, inquiries that had come about before Mr. Ackman joined the board and are continuing. For 2016, Valeant reported a $2.4 billion loss.

Last Monday, Mr. Ackman had had enough. Pershing dumped its Valeant stake at roughly $11 a share.

Insider Trading Accusations

As this calamity played out, Mr. Ackman was also fighting the Allergan lawsuit in California. The plaintiffs were investors who had missed out on gains in Allergan stock in 2014 because they had sold shares without knowing about Valeant’s impending bid, while Pershing Square, which did know about it, was buying Allergan shares. They contended that Valeant and Pershing Square violated securities laws, which prohibit fraudulent, deceptive or manipulative actions in connection with a tender offer.

It would have been very costly for Valeant to finance a takeover of Allergan; instead it struck an agreement on Feb. 25, 2014, allowing Pershing Square to take a nearly 10 percent stake in Allergan to support Valeant’s takeover efforts.

If the bid succeeded, wonderful. But if another offer topped it, Valeant would receive 15 percent of any profits generated by Pershing Square when it sold its Allergan stock to the acquirer.

Pershing set up an entity called PS Fund 1 and began buying. By April 21, it held a 9.7 percent stake in Allergan worth $3.2 billion, court documents show. But the arrangement between Pershing Square and Valeant was not disclosed until the following day, when Valeant said it intended to acquire Allergan.

Discussing the arrangement, Mr. Pearson said, “Having Bill out there in the public” was a plus. “He doesn’t give up.”

Allergan rejected Valeant’s offer and was acquired by Actavis P.L.C., a Dublin-based pharmaceutical company, the next November. Tendering its shares, Pershing Square made a $2.6 billion profit; it gave $400 million of that to Valeant.

Critics of the arrangement cried foul, contending that Pershing had profited from its knowledge of Valeant’s impending bid, essentially front-running the deal, or trading on nonpublic information. And a month later, investors filed suit against Valeant and Pershing Square.

Mr. Ackman and his lawyers have contended that Pershing Square did not violate any insider-trading laws. Still, the case continues to advance under Judge David O. Carter of the Federal Court for the Central District of California.

Lawyers for Mr. Ackman have argued in court that a January order from the Securities and Exchange Commission fining Allergan $15 million for disclosure failures during the Valeant bid supports their case. Because the agency looked hard at the transaction and did not cite violations by Pershing and Valeant in its order, the transaction passed muster, the lawyers contended.

But Judge Carter expressed skepticism. According to the transcript of a Feb. 13 hearing, he questioned why he should accept the S.E.C. order as a finding of fact in the Allergan case. Although he said he would consider the order, he told the lawyers, “Don’t hang your hat on it.”

Of course, cases like the one Mr. Ackman faces often settle for far less than the amount of estimated damages, and Pershing remains a very wealthy fund, with $11 billion in assets. Asked if any of its clients had expressed concern about the case, Pershing said no.

Still, Mr. Ackman recently persuaded Valeant to agree to pay 60 percent of any settlement that might arise in the case.

Struggling Valeant, however, does not have a big cash cushion to contribute toward a money-losing legal case. And the settlement deal, described in a regulatory filing on Feb. 13, expires in November. It is unclear what will happen after that.

A Valeant spokesman provided a statement saying, We are pleased to have entered into this agreement to resolve issues that could have affected our joint defense of the Allergan litigation and enhance our ability to defend against the plaintiffs’ allegations as we continue to work without distraction on nurturing and growing our mutual business interests.”

Wall Street will definitely be watching as Mr. Ackman tries to recover from the Valeant investment. For now, the normally loquacious money manager has gone quiet.