Under the deal, PharMerica's shareholders will receive $29.25 per share in cash, representing a 16.8 percent premium to the company's Tuesday closing price.
PharMerica shares were trading a little short of the offer price at $28.90 before the bell on Wednesday.
Drugstore chain operator Walgreens Boots Alliance will be a minority investor in the newly formed company. The deal, which will take PharMerica private, is expected to close early next year.
PharMerica was created in 2007 by a merger of businesses spun off from AmerisourceBergen and Kindred Healthcare. It provides pharmacy services, ranging from dispensing prescriptions to trying to control drug costs, to nursing homes.
The company also reported second-quarter profit and revenue largely in line with estimates, and said it had canceled its post-earnings conference call in light of the KKR deal.
UBS Investment Bank and Bank of America/Merrill Lynch are serving as financial advisers to PharMerica, while Davis Polk & Wardwell is serving as legal adviser.
Simpson Thacher & Bartlett and Weil, Gotshal & Manges are serving as legal advisers to KKR and Walgreens Boots Alliance, respectively.
Last August, Reuters reported PharMerica was exploring strategic alternatives including a potential sale, citing people familiar with the matter.