NEW YORK — President Donald Trump must pay $2 million for running his crooked Trump Foundation charity that transferred money intended for veterans to his political campaign, a judge ruled Thursday.

Trump agreed to dissolve the foundation in December as part of a deal with New York State Attorney General Letitia James, who alleged the charity was used as an arm of his presidential campaign and a personal piggy bank for the Trump family.

Manhattan Supreme Court Justice Saliann Scarpulla was left to determine what penalty should be imposed on Trump personally for his misuse of the charity. She focused on a January 2016 fundraiser that Trump promoted as an event supporting veterans.

But $2.8 million raised at the event was actually given to the campaign. Trump and his campaign eventually gave that amount to veterans’ charities as questions mounted about the fundraiser.

“Mr. Trump’s fiduciary duty breaches included allowing his campaign to orchestrate the fundraiser, allowing his campaign, instead of the Foundation, to direct distribution of the funds, and using the fundraiser and distribution of the funds to further Mr. Trump’s political campaign,” Scarpulla wrote.

“I direct Mr. Trump to pay the $2,000,000, which would have gone to the foundation if it were still in existence.”

James noted that Trump admitted to personally misusing funds for the charity and now faces restrictions on charitable endeavors going forward.

“The Trump Foundation has shut down, funds that were illegally misused are being restored, the president will be subject to ongoing supervision by my office, and the Trump children had to undergo compulsory training to ensure this type of illegal activity never takes place again,” James said.

“No one is above the law — not a businessman, not a candidate for office, and not even the President of the United States.”

The $2 million will go to approved charitable organizations, including Army Emergency Relief, Children’s Aid Society, City Meals-on-Wheels, United Negro College Fund and the U.S. Holocaust Memorial Museum.

“We are pleased that the Court, in rejecting the Attorney General’s frivolous request for statutory penalties, interest and other damages, recognized that every penny ever raised by the Trump Foundation has gone to help those most in need,” the Trump Foundation said in a statement.

Trump previously defended his charity — and took a shot at James’ predecessor, Eric Schneiderman.

“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 tweeted last year.