A Philadelphia company has agreed to purchase Chartered Health Plan, the managed care company owned by Jeffrey Thompson, a key figure in the investigation of D.C. Mayor Vincent Gray's 2010 campaign.

AmeriHealth agreed to buy the troubled company, which the city seized operational control of last year, for $5 million, along with a commitment to invest an additional $30 million in the Medicaid managed care provider.

A judge must still approve the deal.

"Our consistent goal has been to avoid disrupting health care delivery," William White, the city's insurance, securities and banking commissioner, said in a statement. "The sale of Chartered's assets to a large, stable company can help ensure that."

The company had in recent years moved onto increasingly shaky financial ground: In 2011, it lost more than $9 million.

Chartered, which is the city's largest Medicaid contractor, has been under public scrutiny since federal authorities raided properties with ties to Thompson last March.

Although Thompson has not been charged with any crime, he has been implicated as the financier of an illegal shadow campaign that helped propel Gray into office.