The Weinstein Company's bankruptcy talk has been replaced by deal talk.

With some help from New York A.G. Eric Schneiderman's office, the beleaguered Weinstein Co. board and a group of investors have struck a $500 million deal to sell most of the studio's assets to an investor group led by Maria Contreras-Sweet.

Both sides still have work to do. But the deal could take effect in the coming weeks.

Contreras-Sweet, the former head of the U.S. Small Business Administration, has been working with Ron Burkle and other investors on the bid.

"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 Thursday night.

Her Thursday night statement came just four days after the would-be sellers, the Weinstein Co. board, said that the deal had fallen apart.

They warned that a bankruptcy filing was imminent. But talks continued behind the scenes.

According to a source familiar with the situation, lawyers for both sides were hunkered in a conference room at Schneiderman's office on Thursday, trying to "hash out the details" of the deal.

Around 9:30 p.m., Schneiderman said there was an agreement.

As it stands now, the plan calls for Contreras-Sweet's investor group to acquire 90 to 95% of the studio's assets, including shows like "Project Runway" and a slate of movies.

With those assets, the investors will form a new company, essentially wiping away the stain from the Harvey Weinstein abuse scandal that shook Hollywood last fall.

The Weinstein Co. will continue to exist in some form, as a shell of its former self, possibly for legal reasons.

The new company, which has not yet been named, will include a compensation fund for Weinstein's accusers. Up to $90 million will be allotted for the fund.

Victim compensation was one of the priorities identified by Schneiderman when he sued the studio last month.

The suit severely complicated the deal talks that had been underway between the Weinstein Co. board and the would-be buyers.

But Schneiderman got what he wanted -- including the ouster of Weinstein Co. COO David Glasser from the company.

Related: David Glasser, top executive at Weinstein Company, fired from post

The A.G. office played a role in bringing the two sides together in recent days, as Contreras-Sweet's statement acknowledged on Thursday night.

"This next step represents the best possible pathway to support victims and protect employees," she said. "We are grateful to the New York State Attorney General's office for their efforts in helping us reach an agreement and we are grateful to our investors who have believed in this process and in the compelling value of a female-led company."

Schneiderman said in a statement that the investor group will create "a real, well-funded victims compensation fund, implement HR policies that will protect all employees, and will not unjustly reward bad actors."

The A.G. also said that his lawsuit "remains active and investigation remains ongoing at this time." In other words, the suit against Harvey and Bob Weinstein will continue even if the suit against the studio is resolved.

According to a spokesman for the investor group, most of the employees who remain at Weinstein Co. will be offered positions with the new company.

Contreras-Sweet said the studio will be "led by a board of directors made up of a majority of independent women."