In a pharmacy mega-merger, Walgreens is buying Rite Aid.

The $17.2 billion deal puts together the nation's second and third largest pharmacy chains that combined will have nearly 13,000 U.S. stores. That would catapult the merged company above CVS, which has 7,800 stores.

The deal, which will have to pass antitrust review, is another sign of increased consolidation in health care as the industry changes due to the Affordable Care Act and an aging population.

Rite Aid (RAD) stores would keep their names "initially," but Walgreens plans to create "a fully harmonized portfolio of stores" over time, the company said in announcing the deal Tuesday.

Walgreens (WBA) took over New York-based drugstore chain Duane Reade in 2010. It acquired Boots Alliance, a European pharmacy chain, last year. Walgreens has locations in 11 countries.

One industry analyst said regulators aren't likely to give the deal a green light, considering Rite Aid is the third-largest player in a marketplace already dominated by CVS (CVS) and Walgreens.

CEO Stefano Pessina said in a statement that the deal would allow Walgreens to provide "more heath and wellness solutions...in stores and online."

Pharmacies have increasingly looked to expand their healthcare offerings, looking to create coordinated care systems with doctors and insurance companies.

--CNNMoney's Paul R. La Monica contributed to this report.