Donald Trump’s charitable foundation has reached a deal to shut down amid a legal battle with New York’s attorney general.

Barbara Underwood and the foundation filed a joint stipulation with the court laying out a process for dissolving the charity and distributing its remaining assets to other non-profit groups.

New York filed a lawsuit last spring accusing the foundation of operating like an extension of Mr Trump’s businesses and political campaign. That suit will continue.

Lawyers for the foundation say any infractions were minor. They say they have been trying to shut down the foundation voluntarily for months.

A judge must still sign off on the agreement.

Ms Underwood is a Democrat and is seeking millions of dollars in penalties. She wants the president and his eldest children barred from running other charities.

“This is an important victory for the rule of law, making clear that there is one set of rules for everyone,” Ms Underwood said in a statement.

“We’ll continue to move our suit forward to ensure that the Trump Foundation and its directors are held to account for their clear and repeated violations of state and federal law.”

Mr Trump had long pledged to dissolve the foundation and donate of its remaining funds to charity, but his lawyers said they were thwarted by the attorney general’s office, which wanted oversight over the process.

Tuesday’s agreement came weeks after a New York judge rejected arguments from the foundation’s lawyers that the case was politically motivated and should be thrown out.

Ms Underwood’s predecessor as attorney general, Eric Schneiderman, is another Democrat who started investigating the foundation in 2016 after the Washington Post reported that some of its spending personally benefited the presidential candidate.

Mr Schneiderman ordered the foundation to stop fundraising in New York.

Ms Underwood was appointed to replace Mr Schneiderman in May when he resigned amid allegations he physically abused women.

The lawsuit accused Mr Trump of illegally using the charity’s money to settle disputes involving his business empire and to boost his political fortunes during his run for the White House, including by giving out big grants of other’s people money to veterans’ organisations during the run-up to the Iowa caucuses, the first presidential nominating contest of 2016.

Lawyers for the foundation have said any infractions were minor.