By Jonathan Stempel

NEW YORK (Reuters) - U.S. President Donald Trump and his namesake foundation asked a judge to dismiss a lawsuit by New York's attorney general over the nonprofit's activities, including in the 2016 presidential campaign, calling it a politically motivated attack.

In Thursday night court filings, a lawyer for Trump said Attorney General Barbara Underwood's lawsuit was part of her office's mission to "lead the resistance" against the Republican president, attack him where possible and sue rather than settle.

Underwood, a Democrat, in June said a 21-month probe begun under her predecessor Eric Schneiderman uncovered "extensive unlawful political coordination" by the Donald J. Trump Foundation with Trump's White House campaign, and "repeated and willful self-dealing" to benefit the president.

But the defendants' lawyer Alan Futerfas said "nearly every penny" the foundation raised supported "those most in need," and that the defendants, including Trump's three adult children, did nothing wrong that justified the lawsuit.

He also questioned why Underwood's office had ignored "serious and significant allegations of misconduct" involving the foundation of former U.S. President Bill Clinton, whose wife Hillary was defeated by Trump in the 2016 White House race.

"The appearance of bias and impropriety on the part of this governmental agency, charged with impartial decision-making, is simply overwhelming," Futerfas wrote.

Underwood's spokeswoman Amy Spitalnick said on Twitter that the attorney general "won't back down from holding President Trump and his associates accountable for their flagrant violations of New York law.

"As our lawsuit detailed, the Trump Foundation functioned as a personal piggy bank to serve Trump's business and political interests," she added.

The lawsuit filed in a New York state court in Manhattan seeks to dissolve the Trump foundation, recoup $2.8 million, and ban Trump and his children Donald Jr., Eric and Ivanka from leadership roles in New York charities.

Story continues

Trump had on Twitter called the lawsuit a concoction by "sleazy New York Democrats," and pledged not to settle.

He has also criticized the Clinton Foundation, which is known for helping lower HIV drug costs in developing countries. It has called Trump's attacks also politically motivated.

The president faces a multitude of investigations, and many lawsuits by Democratic-led or -leaning states.

Underwood's lawsuit challenged Trump Foundation transactions including $100,000 paid to a charity to settle a dispute involving Trump's Mar-a-Lago resort, and $10,000 spent on a portrait of Trump that was later hung at one of his golf clubs.

Schneiderman resigned in May after being accused of physically abusing women, which he denied.

(Reporting by Jonathan Stempel in New York; editing by Tom Brown)