NEW YORK — Dollar Tree Inc. has agreed to buy Family Dollar Stores Inc. for about $8.5 billion, creating a discount chain with $18 billion in sales and more locations than Wal-Mart Stores Inc.

Dollar Tree will pay $74.50 a share in cash and stock, 23 percent above Family Dollar's closing price at the end of last week, according to a statement from the companies Monday. Including debt, the deal has a value of about $9.2 billion.

The transaction fulfills the ambitions of two billionaire activist investors, Carl Icahn and Nelson Peltz, who had acquired major stakes in Family Dollar and pushed for a sale. Peltz, head of Trian Fund Management, went so far as to make an unsolicited bid for Family Dollar in 2011 in an attempt to attract other suitors. That offer was turned down and no other bidders emerged at the time.

Family Dollar Chief Executive Officer Howard Levine had previously been reluctant to sell the company his father founded. Still, the business struggled to compete with Dollar Tree, Wal-Mart and other discount chains. That made a deal hard to resist, said Joseph Feldman, an analyst at Telsey Advisory Group in New York.

"It's a more natural evolution than anything else," he said. "Family Dollar has been under some pressure for some time."

Under the agreement, Dollar Tree will pay $59.60 in cash and $14.90 in stock per share for its Matthews, North Carolina-based rival.

Icahn disclosed last month that he'd acquired 9.4 percent of Family Dollar and urged the company to put itself up for sale "immediately." Monday's agreement means his stake increased in value by about $150 million over the weekend. Peltz's Trian owns about 7.3 percent of the company, so that firm's holdings rose about $115 million in value.

Before the deal, Family Dollar had been trying to improve operations by closing about 370 underperforming stores and opening fewer new ones. It also has been lowering prices in a bid to entice shoppers. Dollar Tree, meanwhile, was in far better shape, Feldman said.

"You're taking the best operator in the space and they're adding in the weakest operator," he said.

The companies expect the transaction to close by early 2015 and will contribute to Dollar Tree's cash earnings per share within the first year. The deal will save Dollar Tree about $300 million annually by the end of the third year, the Chesapeake, Virginia-based company said.

"The acquisition of Family Dollar is consistent with our vision to be the leader in value retailing," Dollar Tree CEO Bob Sasser said in the statement.

The combined company will continue to operate under the Dollar Tree, Deals, Dollar Tree Canada and Family Dollar brands, according to the statement. Levine also will remain with the company and report to Sasser.

The sale is the culmination of a strategic review that Family Dollar began late last year, Levine said. Dollar Tree will generate "significant synergies" in areas such as procurement and logistics, and will have improved growth prospects, the companies said.

Family Dollar shareholders will own 12.7 percent to 15.1 percent of the outstanding stock of Dollar Tree when the deal is done. The amount of Dollar Tree shares may be adjusted depending on fluctuations in the stock's price. Trian and Levine, representing a total of about 16 percent of shares, both support today's agreement, according to the statement.

"The combination with Dollar Tree represents the best path forward for Family Dollar and is a great outcome for all of the company's shareholders," Trian said in a separate statement.