Wal-Mart Stores WMT executives could not have been too happy to wake up to the news this morning that dollar store dominator Dollar General DG offered $9.7 billion in an all-cash deal to buy out its smaller, struggling rival Family Dollar Stores FDO , outdoing an earlier, accepted cash-stock offer by Dollar Tree DLTR .

Dollar General is by all accounts a supremely well run retailer: it has reported 24 straight years of same-store sales growth, all the while managing a massive expansion in recent years that has won it millions of shoppers looking to save money. Moreover, its operating profit margin has also improved in the last five years despite the costs of opening thousands of new stores.

That management prowess could turn Family Dollar into a far more formidable rival than it has been on the watch of CEO Howard Levine, whose father founded the chain in 1959. Family Dollar has expanded quickly but also has run into trouble in the last two years by misreading its customers and ramping up its offering of pricier items such as beauty products. It has since backtracked, ramping up its inexpensive offerings.

“Dollar General is going to do a better job of managing those Family Dollar stores,” BB&T Capital Markets analyst Anthony Chukumba told Fortune.

The combined Dollar-General/Family Dollar would have 20,000 stores and annual sales above $28 billion (making it as big as Macy’s M . That would give the company more leverage with suppliers, in addition to saving on overhead costs. Dollar General said its Family Dollar offer would yield $550 million to $600 million a year in synergies, compared to annual savings of $300 million promised in the Dollar Tree bid, announced July 28.

Buying Family Dollar would also give Dollar General an enhanced presence in the East– its 11,000-store fleet is disproportionally represented in the South and Texas– and in urban and suburban areas.

And because Family Dollar and Dollar General overlap a lot more with Wal-Mart than Dollar Tree does, with its single price approach (everything is priced at $1 at most at Dollar Tree), that combination is a bigger potential threat to Wal-Mart, especially as it begins to push its smaller store format expansion to win shoppers that want to go buy staples like milk or toilet paper mid-week at a nearby store rather than deal with a big-box store to get pick up a single item.

Wal-Mart’s smaller format strategy is aimed at arresting a six-quarter streak of no U.S. comparable sales growth. But with about 700 such stores expected to be open by year end, Wal-Mart’s small store fleet would still be a fraction of any of the dollar stores.

“A combined Dollar General-Family Dollar means more stores closer to any Walmart, so they (Walmart) could lose that fill-in trip they’re betting on,” said Brian Sozzi, chief equities strategist at Belus Capital Advisors.

Wal-Mart gets 56% of its sales from grocery and has had to lower prices this year to keep its customers happy. A more efficient Family Dollar, which has been adding more food products as well as tobacco, would become a more formidable rival for that customers even rebranded as Dollar General stores. (Customer loyalty is seen as quite low in this area of retail.)

Wal-Mart Chief Financial Officer Charles Holley stood up for his company’s small-format stores on a call with reporters last week, saying they held their own against the dollar store format by offering some things they don’t.

“It’s a real winning combination when you add the fresh, the gasoline, when you add the RX (prescriptions), and even frozen – we have more frozen than others. And it’s really put us in a good position in the small store sector,” Holley said. Wal-Mart’s small stores posted a 5.6% rise in comparable sales last quarter, easily outperforming its superstores.

But even if Dollar Tree’s offer prevails, Family Dollar would likely be better run and as such, more competition for Wal-Mart, BB&T’s Chukumba added. (And if Dollar Tree wins, it does mean more competition in Canada for Wal-Mart. Unlike Dollar General, Dollar Tree operates a fast growing business north of the border.)

It’s hard to see how Dollar Tree could win a bidding war with Dollar General for Family Dollar, given how much bigger Dollar General is, and the fact it is offering a higher bid all in cash. (Dollar General is more than twice as big in terms of store count and has revenue about 33% higher than Dollar Tree.)

Dollar Tree hasn’t yet countered with a higher offer, but however this dollar store soap opera ends, Wal-Mart’s life is about to get tougher.

Here’s a video on the dollar store bidding wars

Updates to include comments from Wal-Mart last week on its small format business and add video clip.