NEW YORK — A New York judge has rejected a bid by Donald Trump’s lawyers to throw out a state lawsuit that alleges the president disregarded the law in running his charitable foundation and instead used it as a wing of his presidential campaign.

But, in the ruling posted Friday, State Supreme Court Justice Saliann Scarpulla reiterated that she would be forced to drop Trump from the lawsuit if a state appeals court weighing an unrelated case decides that a sitting president can’t be sued in state court.

In the meantime, Scarpulla said, New York Attorney General Barbara Underwood’s lawsuit alleging that Trump used the nonprofit Trump Foundation’s money to settle business disputes and boost his political fortunes can move forward.

The suit seeks $2.8 million in restitution, the foundation’s disbandment and a 10-year ban on Trump running any charities.

Scarpulla rebuffed the contention of Trump’s lawyers that the lawsuit was politically motivated. Given the seriousness of the allegations, she said, there was no basis for finding that “animus and bias were the sole motivating factors” for the lawsuit.

Underwood welcomed the ruling.

“As we detailed in our petition earlier this year, the Trump Foundation functioned as little more than a checkbook to serve Mr. Trump’s business and political interests,” Underwood said in a statement. “There are rules that govern private foundations — and we intend to enforce them, no matter who runs the foundation.”

Trump’s lawyer, Alan Futerfas, said he’s confident the president’s side will ultimately prevail.

“The decision means only that the case goes forward,” Futerfas said in a statement. “As we have maintained throughout, all of the money raised by the Foundation went to charitable causes to assist those most in need.”

Former New York Attorney General Eric Schneiderman started investigating the Trump Foundation in 2016 after The Washington Post reported that its spending personally benefited the presidential candidate. Schneiderman ordered the foundation to stop fundraising in New York.

Underwood was appointed to replace Schneiderman in May, when he resigned amid allegations that he physically abused women he dated. Schneiderman, a Democrat, has said he accepts “full responsibility” for his conduct and apologized “for any and all pain” he caused.

Whether Trump remains a defendant in the Trump Foundation case hinges on how a state appeals court rules in former “Apprentice” contestant Summer Zervos’ defamation lawsuit against the president.

Trump’s lawyers argue that a sitting president can’t be sued in state court over conduct outside official duties, something Scarpulla and the trial judge in the Zervos case reject.

Scarpulla wrote in her ruling that allowing the Trump Foundation case to proceed in state court is “entirely consistent” with the U.S. Supreme Court’s 1997 ruling that forced then-President Bill Clinton to face a federal sexual harassment lawsuit concerning an alleged encounter while he was governor.

If the appellate division were to side with Trump in the Zervos case, the Trump Foundation lawsuit could still proceed against the foundation and Trump’s adult children, who were board members.