Donald Trump had no choice but to blow $10,000 in charity money on a giant painting of himself — because no one else wanted it, his lawyers claimed in court Thursday.

Trump picked up the infamous painting — now at the center of a lawsuit brought by the state attorney general who alleges suspect spending by the charity — during a 2014 auction benefiting The Unicorn Foundation at his Mar-a-Lago country club in Florida.

“So Mr. Trump donates $10,000 to start the bidding, and then when the bidding goes on and no one else bids, they’re stuck with the painting,” his attorney Alan Futerfas told Manhattan Supreme Court Judge Saliann Scarpulla as he asked for the case to be dismissed.

And so the “Art of the Deal” author got the raw end of the deal and wound up having to plunk down $10,000 on the portrait. But rather than fork over the dough himself, Trump billed his own Donald J. Trump Foundation for the cost.

Prosecutors say Trump also used charitable foundation money to pay off his creditors, decorate one of his golf clubs with the portrait, and boost his presidential campaign.

“They’re making a mountain out of a molehill,” Futerfas said of the allegations.

Beyond the painting, Assistant Attorney General Yael Fuchs said that in 2016, the foundation was “used to collect and distribute funds at the direction and for the benefit of the Trump campaign.”

The foundation and the campaign worked hand in hand to stage a televised “Trump for Vets” event in Iowa a week before the state’s caucuses. The event brought in $5.6 million of tax-free donations — $2.8 million of which went straight into foundation coffers while the remainder went to charitable groups, according to the AG.

“I think it’s beyond dispute that these were improper self-dealing transactions,” Fuchs said.

But Futerfas countered that “every dime, every penny” from the fundraiser went to veterans charities.

“Candidates can go out and raise money for charity. That’s absolutely proper,” Futerfas said.

The judge said the question was whether the Trump campaign directed payment of the proceeds from the foundation to specific charities in order to curry favor with voters — which would be illegal.

Scarpulla said she’d wait to rule on the case until a Manhattan appeals court determined whether a sitting president could be sued in state civil court.