A New York judge on Thursday ordered President Trump to pay $2 million in damages for misusing funds from a tax-exempt charity — taking the charity’s money to pay debts for his for-profit businesses, to boost his 2016 campaign and to buy himself art, according to court documents.

That order, from state judge Saliann Scarpulla, settled a lawsuit filed against Trump last year by the New York attorney general.

The lawsuit — based on information first uncovered by The Washington Post — alleged “persistently illegal conduct” at the Donald J. Trump Foundation, where Trump served as president for 32 years.

As part of the settlement, Trump also agreed to disburse the $1.8 million remaining in the foundation to a set of charities, and to shutter it for good. In a statement signed by Trump’s attorney, the president admitted to poor oversight of the charity and to seven specific instances where its money was misspent.

“Mr. Trump owed fiduciary duties to the Foundation,” Scarpulla wrote in an order, meaning duties to safeguard the foundation’s money. “Mr. Trump breached his fiduciary duty to the Foundation.”

New York Attorney General Letitia James (D) had asked Scarpulla to make Trump pay $2.8 million, but Scarpulla said she was reducing that payment to $2 million.

The reason: The president had agreed to mend his ways, agreeing to extra monitoring of any future charitable activities in New York, so that “the conduct which engendered this petition should not occur in the future,” Scarpulla said.

Trump’s three eldest children — Ivanka, Donald Jr. and Eric — were also named in the original lawsuit, because they were board members at the Trump Foundation. The board was required to oversee the foundation’s spending. In reality, it did not meet at all for 19 years, from 1999 to 2018.

The three children were required to take an “in-person interactive” training class in how to be a better board member, and the suit against them was dismissed, court documents say.

In a statement, James called the settlement “a major victory.”

“My office will continue to fight for accountability because no one is above the law — not a businessman, not a candidate for office, and not even the President of the United States,” James said in a statement.

In his own statement, Trump’s attorney, Alan Futerfas, attacked James’s lawsuit as “politically motivated.” (It was filed by James’s predecessor, Barbara Underwood, an unelected career official who took over after Attorney General Eric Schneiderman (D) resigned in scandal.)

“Now that this matter is concluded, the Trump Foundation is proud to make this additional contribution,” Futerfas said. The money from Trump will go to charities including the Children’s Aid Society, the United Negro College Fund and the U.S. Holocaust Memorial Museum, according to the attorney general’s office.

The Post’s coverage began in early 2016 after a Post reporter saw Trump give away a Trump Foundation check during a campaign rally in Waterloo, Iowa. That was notable because federal law prohibits charities’ money from being used to help political campaigns.