The Trump Foundation — the charitable foundation started by President Donald Trump years before he became a presidential candidate, which New York's top prosecutor said exhibited a "shocking pattern of illegality" — will dissolve under pressure from the state's attorney general, according to a court filing.

The foundation will give away its assets to other non-profit organizations in the next 30 days, according to an agreement between state prosecutors and the Trump Foundation, according to an agreement reached between New York Attorney General Barbara Underwood and the Trump Foundation.

It does not stop the lawsuit the AG’s office has filed against the foundation, which was formed in 1987, and that action will continue.

“Our petition detailed a shocking pattern of illegality involving the Trump Foundation — including unlawful coordination with the Trump presidential campaign, repeated and willful self-dealing, and much more," Underwood said in a statement.

"This amounted to the Trump Foundation functioning as little more than a checkbook to serve Mr. Trump’s business and political interests."

Only "reputable" charities, approved by Manhattan Supreme Court Justice Saliann Scarpulla and the attorney general's office, will be able to receive funds from the soon-to-be-defunct charity, according to Underwood.

"Today’s stipulation accomplishes a key piece of the relief sought in our lawsuit earlier this year. Under the terms, the Trump Foundation can only dissolve under judicial supervision — and it can only distribute its remaining charitable assets to reputable organizations approved by my office," Underwood said in a statement.

“This is an important victory for the rule of law, making clear that there is one set of rules for everyone. We’ll continue to move our suit forward to ensure that the Trump Foundation and its directors are held to account for their clear and repeated violations of state and federal law.”

Trump Organization attorney Alan Futerfas told NBC News on Tuesday that his clients are “happy we could get it resolved” with Underwood's office.

Futerfas also said his clients were the ones who sought a dissolution in the first place.

In a prepared statement, Futerfas claimed the foundation has been a successful charity that's "distributed approximately $19 million, including $8.25 million of the President’s personal money, to over 700 different charitable organizations with virtually zero expenses."

Futerfas accused the state prosecutors of grandstanding.

"The NYAG’s inaccurate statement of this morning is a further attempt to politicize this matter," he said.

The White House declined to immediately comment.