Dollar Tree Inc. agreed to buy Family Dollar Stores Inc. for $8.5 billion. (Michael Nelson/EPA)

When Family Dollar announced plans in April to shutter 370 stores and slash its prices after another disappointing earnings report, most industry observers were convinced it was only a matter of time before the struggling discount retailer changed hands. The only question was who would buy it.

Hardly anyone guessed it would be Dollar Tree, a competing discount retailer. But in a surprising move announced Monday, Dollar Tree will acquire Family Dollar in an $8.5 billion cash-and-stock deal.

The merger brings together the nation’s second and third largest discount retailers, creating an industry giant with 13,000 stores in the U.S. and Canada and more than $18 billion in yearly sales.

The deal reflects growing pressure on the once-thriving discount-retailer model. Despite their differences, both companies, as well their thriving competitor Dollar General, cater to a demographic of consumers that felt the effects of the recession more severely and recovered from it more slowly. Amid slow wage growth and recent federal cuts to food stamps and unemployment benefits, many once-loyal dollar-store customers are staying home.

Family Dollar’s profits fell one-third in its most recent quarter compared to the same period last year, while Dollar Tree profits have been flat.

The activist investor Carl Icahn, a shareholder who had publicly pressured N.C.-based Family Dollar to sell itself last month, claimed Monday’s deal as a victory. He said in a statement that the merger signified a “a big win for all shareholders of Family Dollar and yet another validation of the activist investment philosophy in general.” For its part, Family Dollar said it had begun exploring the deal this past winter.

The two companies will maintain their separate brands. While Dollar Tree caters to a suburban customer base and keeps all prices at a dollar or less, Chesapeake, Va.-based Family Dollar prices some of its merchandise above a dollar and attracts lower-income consumers in urban and rural areas.

The deal further crowds the already packed marketplace with small-box discount stores. Facing their own struggles, big retailers like Wal-Mart and Target in recent years started opening smaller stores in an effort to compete with their dollar-store competitors.

Brian Sozzi, an analyst at Belus Capital Advisors, said in an article for The Street that Wal-Mart had made a big mistake in not buying Family Dollar. He called it “the first major failure of the Doug McMillon administration,” in reference to Wal-Mart’s new chief executive.

But Jan Rogers Kniffen, a consultant to investors and retail companies, said he was skeptical that the deal represented a blow to Wal-Mart.

“They want to participate, they want to play, they want to be competitive in this space,” Kniffen said. “But this business is not big enough to change Wal-Mart’s fate.”

Analysts offered tempered praise of Dollar Tree’s move, saying it gave the retailer a chance to target new demographics and ward off its competitors. Yet the opportunity is accompanied by significant risks and challenges, they said, as Dollar Tree will be tasked with reversing Family Dollar’s flagging fortunes while simultaneously learning a business model markedly different than its own. “It’s very difficult juggling act, and I would say they would have earned their space in the retail hall of fame if they’re capable of doing that,” said Dutch Fox, a discount retail analyst at FBR. Family Dollar’s chief executive Howard Levine, will report to Dollar Tree’s chief executive Bob Sasser.

To succeed, analysts said, Family Dollar’s new management will have to lure low-income consumers back into the retailer’s stores at pre-recession levels.

“The turnaround story at Family Dollar definitely hinges on there being continued growth in that low-end space,” Fox said. “If five years from now the sales per square foot of Family Dollar don’t vastly improve, it would be difficult to look back at this merger and call it a rousing success.”

Family Dollar’s stock jumped about 25 percent by closing time on Monday, and Dollar Tree’s stock rose by 1.2 percent.