President Donald Trump on Wednesday blasted the deal to dissolve his namesake charitable foundation after New York's top prosecutor said it exhibited a "shocking pattern of illegality."

The Trump Foundation, started by Trump years before he became a presidential candidate, agreed to disband and give away its assets, according to the agreement announced Tuesday between New York Attorney General Barbara Underwood and the foundation.

Trump, in a series of tweets on Wednesday, praised the "great work" his foundation did and called the former New York attorney general, Eric Schneiderman, "shady" and a "sleazebag." Schneiderman resigned earlier this year after four women accused him of abuse.

"The Trump Foundation has done great work and given away lots of money, both mine and others, to great charities over the years — with me taking NO fees, rent, salaries etc.," Trump said in a tweet.

The Trump Foundation has done great work and given away lots of money, both mine and others, to great charities over the years - with me taking NO fees, rent, salaries etc. Now, as usual, I am getting slammed by Cuomo and the Dems in a long running civil lawsuit started by..... — Donald J. Trump (@realDonaldTrump) December 19, 2018

"Now, as usual, I am getting slammed by Cuomo and the Dems in a long running civil lawsuit started by sleazebag AG Eric Schneiderman, who has since resigned over horrific women abuse, when I wanted to close the Foundation so as not to be in conflict with politics," he added, referring to New York Gov. Andrew Cuomo, a Democrat.

Underwood brought the lawsuit against Trump and his three eldest children — Donald Jr., Ivanka and Eric — and is also pursuing a lawsuit to bar the Trumps from serving on the boards of other New York charities.

The suit accuses the Trump Foundation of a "shocking pattern of illegality" that includes "unlawful coordination with the Trump presidential campaign, repeated and willful self-dealing, and much more," according to a statement from Underwood.

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

The foundation will give away its assets to other nonprofit organizations in the next 30 days, according to an agreement between state prosecutors and the Trump Foundation.

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.

The agreement does not stop the lawsuit, and that action will continue.

Trump on Wednesday called the agreement a "total double standard of 'justice'" because Underwood "does little else but rant, rave & politic against me." He also slammed the state's incoming attorney general, Letitia James, who told NBC News last week she plans to launch sweeping investigations into Trump and members of his family.

"In any event, it goes on and on & the new AG, who is now being replaced by yet another AG (who openly campaigned on a GET TRUMP agenda), does little else but rant, rave & politic against me. Will never be treated fairly by these people — a total double standard of “justice'," Trump wrote.

In a statement Wednesday, Amy Spitalnick, a spokeswoman for Underwood, defended Underwood's career credentials and the basis for the lawsuit, calling her "a career prosecutor and public servant who served as U.S. Solicitor General, clerked for Thurgood Marshall, and has argued before the Supreme Court 20 times."

"A.G. Underwood believes that there should be one set of rules for everyone — no matter who they are. That’s why she filed suit against the Trump Foundation, after an investigation found a shocking patter of flagrant and repeated illegality — including willful self-dealing to serve Mr. trump and his business and political interests.”

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 that statement, Futerfas claimed the foundation "distributed approximately $19 million, including $8.25 million of the president’s personal money, to over 700 different charitable organizations with virtually zero expenses" and accused the state prosecutors of grandstanding.