The Donald J. Trump Foundation has agreed to dissolve under judicial supervision and to give away its remaining funds while New York state conducts an investigation into whether the president's namesake charity misspent donations.

"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," New York Attorney General Barbara Underwood said Tuesday. She said the foundation had functioned "as little more than a checkbook to serve Mr. Trump's business and political interests."

Following the announcement, Trump lawyer Alan Futerfas told CNBC, "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. Unfortunately, the NYAG sought to prevent dissolution for almost two years, thereby depriving those most in need of nearly $1.7 million."

The White House referred questions about the foundation to the Trump Organization.

Under the dissolution agreement, after the judge approves the deal, the Trump Foundation will have 30 days during which to give away the balance of its funds, $1.75 million, to charities.

The list of charities set to receive funds from the foundation will need to be approved by the court and the attorney general's office.

Underwood also said her office will continue to pursue its lawsuit against the charity, the president and his three eldest children "to ensure that the Trump Foundation and its directors are held accountable for their clear and repeated violations of state and federal law."

The dissolution announced Tuesday marked the culmination of nearly two years of investigative reporting by national news organizations, led by The Washington Post's David Fahrenthold, into how the Trump Foundation operated.

While the charity never represented more than a small portion of Trump's financial portfolio, it was emblematic of how the Trump family approached many of its financial arrangements. Bankrolled by donations from Trump's friends and business associates, the foundation gave away money in Trump's name so that Trump could publicly claim credit even though he essentially was giving away other people's money.

To this day, the motives of many of the donors to the Trump foundation remain unknown, including those of pro-wrestling moguls Vince and Linda McMahon, who gave millions of dollars to the foundation. Linda McMahon currently serves in Trump's Cabinet as administrator of the Small Business Administration.

Questions about where the foundation's money came from are dwarfed, however, by questions about where it went. IRS records show that Trump used the foundation's money to pay legal settlements for his for-profit company, to bolster his political career, and to grease the wheels within his business, political and social circles.

The Post's David Fahrenthold writes:

The largest donation in the foundation's history — a $264,231 gift to the Central Park Conservancy in 1989 — appeared to benefit Trump's business: It paid to restore a fountain outside Trump's Plaza Hotel. The smallest, a $7 foundation gift to the Boy Scouts that same year, appeared to benefit Trump's family. It matched the amount required to enroll a boy in the Scouts the year that his son Donald Trump Jr. was 11.

Trump's three eldest children, Donald Trump Jr., Ivanka Trump and Eric Trump, all served as directors of the foundation, although it was later revealed that they had never actually held a board meeting.