Walgreens says about a quarter of its stores are unprofitable. Big pharmacy chains are struggling with growing retail competition and lower prescription payouts.
CVS will start filling prescriptions for mifepristone in Massachusetts and Rhode Island. Walgreens will start in New York, Pennsylvania, Massachusetts, California and Illinois.
California Gov. Gavin Newsom said that the state would halt business with Walgreens after the pharmacy giant agreed to stop distributing mifepristone in some red states amid legal pressure.
The 20 states where Walgreens won't sell mifepristone include some where abortion remains legal. It's not clear whether other retail pharmacies will follow suit.
Walgreens will limit online orders of children's fever and pain medicine to six items "to help support availability and avoid excess purchases." At CVS stores, purchases will be limited to two.
CVS would pay about $5 billion and Walgreens more than $5.5 billion, though neither company has admitted wrongdoing. States have until the end of the year to accept the terms of the settlement.
Amazon launches an online pharmacy, sending shares of CVS, Walgreens and Rite Aid tumbling. Amazon has pushed to compete with Walmart and major pharmacy chains that have long offered home delivery.