NEW YORK (AP) — Walgreens Boots Alliance says it has agreed to be acquired by private equity firm Sycamore Partners as the struggling retailer looks to turn itself around after years of losing money.

Walgreens said Thursday that Sycamore will pay $11.45 per share, giving the deal an equity value just under $10 billion. Shareholders could eventually receive up to another $3 per share under certain conditions.

A buyout to take the drugstore chain private would give it more flexibility to make changes to improve its business without worrying about Wall Street’s reaction. The company has already been making some big changes as it seeks to turn around its business. Walgreens has been a public company since 1927.

Walgreens, founded in 1901, has been dealing with thin prescription reimbursement, rising costs, persistent theft and inflation-sensitive shoppers who are looking for bargains elsewhere. Walgreens is in the early stages of a plan to close 1,200 of its roughly 8,500 U.S. locations.

The Deerfield, Illinois, company had already shed about a thousand U.S. stores since it grew to nearly 9,500 after buying some Rite Aid locations in 2018.

The company also said last August that it was reviewing a U.S. health care operation it had expanded aggressively, and it might sell all or part of its VillageMD clinic business. That announcement came less than two years after the company said it would spend billions to expand it.

Shares of Walgreens shed nearly two thirds of their value last year. Walgreens said the transaction price represents a nearly 30% premium to the share price in December when reports of a deal first surfaced. Walgreens CEO Tim Wentworth confirmed in January that a sale process for the business was underway. Including debt, the value of the deal is just under $24 billion, the company said.

Walgreens said earlier this year it was making progress improving prescription reimbursement.

Walgreens has also taken steps to preserve cash. It said in January that it was suspending a quarterly dividend it has offered for more than 90 years, and it's been reducing its stake in the drug distributor Cencora this year to get cash in part to pay down debt.

Ultimately, the company has to improve its cash flow, whether it remains publicly traded or goes private, Leerink Partners analyst Michael Cherny said in a Feb. 23 research note.

“Management has not been shy about its push to improve the cash flow generation profile as part of the turnaround plan,” the analyst wrote. “Without cash flow, none of the value cases work.”

Walgreens Boots Alliance Inc. also runs nearly 3,700 international stores, with locations in the United Kingdom, Mexico, Thailand and Ireland.

The Walgreens buyout comes after competitor Rite Aid emerged last September as a private company from a Chapter 11 bankruptcy reorganization. Remaining publicly traded drugstore operators include the nation’s largest, CVS Health Corp., and retailers like Walmart and the grocer Kroger that run pharmacies at many of their locations.