President Trump has agreed to dissolve his charity and give away the remaining $1.75 million in its account in the middle of an investigation of how it used its assets, New York state Attorney General Barbara Underwood said Tuesday.

Underwood said her investigators found “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.”

“This is an important victory for the rule of law, making clear that there is one set of rules for everyone,” she added in a statement.

But lawyers for Trump said he has been trying to close the charity since becoming president — and it was Underwood who blocked that for political reasons.

Underwood said a lawsuit she filed against the charity would continue as her office seeks $2.8 million in restitution.

She also asked a judge to ban Trump and his kids who run the charity — daughter Ivanka and sons Eric and Donald Jr. — from serving on the boards of other charitable institutions.

The AG’s complaint said the charity’s board, incorporated in 1987, never held a meeting.

She accused the foundation of using its funds “to promote Mr. Trump’s properties, purchase personal items, advance Mr. Trump’s presidential election campaign . . . and settle certain personal legal obligations.”

The AG’s office alleged that Trump effectively “ceded control” of his foundation to his presidential campaign to promote an Iowa fundraiser for vets just before the Iowa presidential caucus.

Trump’s then-campaign manager Corey Lewandowski decided which groups got the funding.

The complaint called the use of the foundation for election purposes “self dealing,” adding that “the campaign garnered expensive, vote-getting publicity that Mr. Trump would have otherwise paid himself.”

Trump also used the charity’s money to make a $25,000 political donation to Florida Attorney General Pamela Bondi.

The complaint said the foundation was used to pay for personal or company legal bills.

The foundation also spent $20,000 to buy a large portrait of Trump in 2007.

Trump’s lawyer accused Underwood of playing politics.

“Contrary to the NYAG’s misleading statement issued earlier today, the Foundation has been seeking to dissolve and distribute its remaining assets to worthwhile charitable causes since Donald J. Trump’s victory in the 2016 Presidential election,” said attorney Alan Futerfas.

“Unfortunately, the NYAG sought to prevent dissolution for almost two years, thereby depriving those most in need of nearly $1.7 million. Over the past decade, the Foundation is proud to have distributed approximately $19 million, including $8.25 million of the President’s personal money, to over 700 different charitable organizations with virtually zero expenses.

“The NYAG’s inaccurate statement of this morning is a further attempt to politicize this matter.”

The largest donation in the foundation’s history was a $264,231 gift to the Central Park Conservancy in 1989 — used to restore a fountain outside the Plaza Hotel that Trump owned at the time.