An investor group backed by billionaire Ron Burkle has reached a $500 million deal with the Weinstein Co. that will spare the troubled company from bankruptcy.

The deal came together in a marathon negotiation Thursday in the office of New York Attorney General Eric Schneiderman. The Weinstein Co. board, including chairman Bob Weinstein, sat down with Burkle and his partner, former Small Business Administration chief Maria Contreras-Sweet, with Schneiderman helping to seal the deal.

“Our team is pleased to announce that we have taken an important step and have reached an agreement to purchase assets from The Weinstein Company in order to launch a new company, with a new board and a new vision that embodies the principles that we have stood by since we began this process last fall,” Contreras-Sweet said in a statement.

The negotiations continued over minor points even after Contreras-Sweet released her statement. Three hours later, the Weinstein Co. board confirmed the deal.

“We are pleased to announce that we have entered into an agreement to sell the assets of The Weinstein Company to an investor group led by Maria Contreras-Sweet and Ron Burkle,” the board said. “The deal provides a clear path for compensation for victims and protects the jobs of our employees. We greatly appreciate the efforts of Attorney General Schneiderman and his staff, Maria Contreras-Sweet, Ron Burkle and his team at Yucaipa for bringing about this agreement. We consider this to be a positive outcome under what have been incredibly difficult circumstances.”

The deal comes after the transaction nearly died twice in the space of two weeks. On Feb. 11, the buyers almost walked away when Schneiderman’s office filed a discrimination complaint that sought oversight and conditions on the sale. After talks restarted, the Weinstein Co. announced on Feb. 25 that they were backing out and pursuing bankruptcy, and accused Burkle and Contreras-Sweet of failing to negotiate in good faith.

The most recent sticking point was Burkle’s reluctance to provide $7 million in upfront capital to keep the company on its feet while the transaction is pending. A source told Variety that the agreement comes with a 40-day closing period. The interim funding issue has been resolved, according to a source. Another issue was the Weinstein Co.’s refusal to provide an opinion letter guaranteeing that they had the right to sell the company. The concern was that Harvey Weinstein, who resigned his board seat last fall and would see his equity wiped out in the sale, might have standing to contest the transaction.

Following the collapse of the talks over the weekend, Burkle and Contreras-Sweet sought to revive negotiations with the aid of the attorney general. The Weinstein Co. was initially reluctant to reengage, but the company’s employees were angry and fearful of layoffs that would result from bankruptcy.

Schneiderman objected to the original terms of the sale, saying that a proposed fund for Harvey Weinstein’s sexual harassment victims was inadequate. After his intervention, the parties agreed to increase the fund to $90 million. Schneiderman also sought assurances regarding the company’s sexual harassment policies, and had objected to a plan to put David Glasser, the company’s COO under Weinstein, in the CEO role. Glasser was subsequently fired “for cause” by the board, but Burkle has continued to hold out the possibility of keeping him on board.

In a statement on Thursday night, Schneiderman said he was “pleased to have received express commitments from the parties that the new company will create a real, well-funded victims compensation fund, implement HR policies that will protect all employees, and will not unjustly reward bad actors.”

“We will work with the parties in the weeks ahead to ensure that the parties honor and memorialize these commitments prior to closing,” he continued. “Our lawsuit remains active and (the) investigation remains ongoing at this time.”

In addition to Burkle and Contreras-Sweet, other investors include Lantern Capital, based in Dallas, and others yet to be announced. The buyers plan to rebrand and install a female-majority board of directors in an effort to cleanse the stain of the Weinstein scandal. A new name has not been selected, though at one point the investors were said to be leaning toward Wonder Hill.

Burkle, the managing partner of Yucaipa Cos., has dabbled in the movie business in the past, investing in a handful of Weinstein Co. projects. Contreras-Sweet is a Hollywood outsider, without previous experience in the entertainment business. Before serving in the Obama administration, she worked in banking and corporate public affairs, and was an official in the administration of Gov. Gray Davis. She is not particularly wealthy, with an estimated net worth between $326,000 and $815,000, according to her federal financial disclosure reports.

Contreras-Sweet will have the challenge of stabilizing a company that went into freefall shortly after the New York Times reported on Weinstein’s history of sexual harassment on Oct. 5. The company, already ailing, was forced to cancel releases and saw deals for TV shows collapse. The company has been hit with numerous lawsuits from actresses alleging complicity with Weinstein’s harassment, and from business partners alleging non-payment of bills. The company was forced to sell off “Paddington 2” just to make payroll, and its American Express corporate credit cards were frozen.

Under the deal, the buyers are expected to assume $225 million in existing debt under a credit facility. The buyers will also pay out $275 million in equity, of which approximately $100 million will become operating capital for the new company. The balance of the cash infusion will be used to pay off other debts and unpaid bills, as well to establish the settlement fund for Weinstein’s victims. The equity holders of the old company, including WPP and Goldman Sachs, will be wiped out in the deal.

Bob Weinstein will depart the company under the agreement, and take the Dimension brand with him as well as one unreleased film, “Polaroid.” The investor group will take possession of the Weinstein’s Co.’s 277-film library, including the Dimension titles. Another 125 titles were mortgaged to stave off creditors in 2010, and those will remain encumbered after the sale.

Contreras-Sweet plans to retain the entire Weinstein Co. workforce, and even expand the L.A. and London offices. With the infusion of new cash, the company plans to announce release dates for several films that are all but completed, including “The Current War” starring Benedict Cumberbatch and Michael Shannon.