On Monday, CVS announced that Walmart would be leaving the drugstore network of its pharmacy benefit unit, CVS Caremark because the two could not come to an agreement on how much the PBM unit would pay Walmart pharmacies to fill prescriptions. Analysts said a break-up would have resulted in more than 50 million CVS Caremark commercial and Medicaid plan members no longer being reimbursed for filling prescriptions at Walmart.

Just days after announcing an impasse in reimbursement negotiations, CVS Health and Walmart said the companies had resolved their dispute, averting a split between two of the nation's largest pharmacy retailers.

The hostile public dispute comes at a time when pharmacy benefit managers are driving hard bargains with drugmakers and drugstores, in order to demonstrate that they can lower costs for consumers.

"The resolution speed of today's announcement is surprising … and likely points to the general negotiating strength that PBMs have," wrote Evercore ISI analyst Ross Muken in a note to clients. He noted that in 2012 when Walgreens Boots Alliance was shut out of network in a pricing dispute it quickly lost market share.

"Consumers will largely move wherever their insurance is accepted, and so Walmart would have likely lost out on the vast majority of these (prescriptions)," Muken said.

But the split would not have been without risk for CVS, which is embarking on an ambitious plan to turn its pharmacies into a one-stop health-care shop for prescriptions and preventive medical care at its clinics, after closing its acquisition of health insurer Aetna. It could have made its PBM unit's contract renewals with some large employers and smaller health insurers more difficult. CVS is one of the largest PBMs.

"Without access to Walmart's 4,700+ pharmacy locations, we believe some (health) plan sponsors may be less willing to contract with CVS Caremark and other PBMs and plans may be more likely to include Walgreens in their networks," wrote Leerink analyst David Larsen in a note to clients at the start of the week.

Terms of the newly renegotiated rate deal were not disclosed, CVS said in a statement that it was a multi-year agreement.

CVS shares rose more than 2 percent in trading Friday.