William Ackman is ending his crusade against Herbalife Ltd., in what amounts to a bruising defeat in one of Wall Street’s longest-running, most expensive and acrimonious fights.

The activist investor has largely exited his $1 billion, five-year bet against the nutritional products company, sources familiar with the matter said.

It isn’t clear how much Mr. Ackman’s Pershing Square Capital Management LP lost, but it is likely in the hundreds of millions. Herbalife stock, which Mr. Ackman contended would go to zero, hit a new high of nearly $96 Wednesday on the news, earlier reported by CNBC. The shares closed up 6.3% at $92.10.

Mr. Ackman first alleged in December 2012 that Herbalife, which sells through a network of distributors, was an illegal pyramid scheme and would be shut down by the government. He had personally pledged to take his campaign “to the end of the earth,” though he added that Pershing Square would abandon the bet if it got too risky. The company says it is a legal multi-level-marketing organization and fought him at every turn, accusing the investor of market manipulation, which Mr. Ackman denied.

Mr. Ackman’s campaign did lead to some major changes and spurred the Federal Trade Commission to investigate Herbalife. The climax of the drama came when Herbalife settled the probe in July 2016, agreeing to a $200 million penalty over claims it misrepresented earnings prospects for distributors. While the government was critical, it didn’t declare the company a pyramid scheme. The government forced changes in how the company operates to prove customers actually buy its products, but allowed Herbalife to continue operating.