The Donald J Trump Foundation closed down in 2018. Prosecutors had accused it of working as “little more than a chequebook” for Mr Trump’s interests.
Charities such as the one Mr Trump and his three eldest children headed cannot engage in politics, the judge ruled.
Mr Trump hit out at the ruling, saying “every penny” went to charity.
“I am the only person I know, perhaps the only person in history, who can give major money to charity ($19m), charge no expense, and be attacked by the political hacks in New York State,” he wrote in a statement posted to Twitter.
He accused New York’s attorney general, Letitia James, who brought the civil lawsuit, of “deliberately mischaracterising this settlement for political purposes”.
Judge Saliann Scarpulla said Mr Trump had “breached his fiduciary duty” by allowing funds raised for US veterans to be used for the Iowa primary election in 2016.
“I direct Mr Trump to pay the $2,000,000, which would have gone to the Foundation if it were still in existence,” she wrote, saying it must be paid by Mr Trump himself and should go to eight charities he has no relationship to.
Mr Trump said the case had been resolved and that he was “happy to donate” $2m to the Army Emergency Relief, Children’s Aid Society, City Meals-on-Wheels, Give an Hour, Martha’s Table, United Negro College Fund, United Way of Capital Area and the US Holocaust Memorial Museum.
Ms James said Mr Trump had admitted to “personally misusing funds at the Trump Foundation”.
She had asked Judge Scarpulla to ban Mr Trump from ever running a charity again. However, this was not imposed.
Donald Trump Jr, Eric Trump and Ivanka Trump – who were also directors of the Trump Foundation – are required to undergo mandatory training “on the duties of officers and directors of charities”, Ms James said.
The case was opened following an investigation into the Trump Foundation by the Washington Post in 2016.