Rudy Giuliani is working for free as President Trump’s lawyer — and losing money over it — but it’s not for patriotic reasons, his estranged wife’s lawyer said Thursday.

The former New York City mayor could be “purposely lowering his income’’ to dodge shelling out a higher settlement to his ex in their bitter divorce, the lawyer said.

Judith Nathan Giuliani’s lawyer, Bernard Clair, made the allegation during a heated divorce hearing between the pair in Manhattan Supreme Court.

“Not only is [Giuliani] working pro bono for the president, for this individual, but it’s costing him money,” Clair said. “Not only does he work for free, but all of his expenses every time he goes down to Washington DC, every time he travels for the president, it comes out of his own pocket, and he won’t say how much it’s costing him.”

Still, all of the trips that Giuliani makes on behalf of Trump aren’t a complete financial loss for the former mayor, Clair noted.

“What [Giuliani] does, your Honor, is when he is going to work for the president, he bundles, for lack of a better word, clients who do have to reimburse him,” Clair said.

For example, “The Warsaw trip is for the president, but it’s also for someone else because he’s giving a speech,” Clair said, referring to Giuliani’s visit earlier this year to Poland.

“I asked him a number of times, ‘Please provide us with your 17 credit cards that you use. Tell me how you are being reimbursed.’ ‘I don’t know,‘ he says.”

Giuliani and Judith — who split in April 2018 and reportedly have $30 million in property and other assets — were in court fighting over the spending of a joint $5 million account.

“You have a man who comes into court saying ‘woe is me’ financially,” Clair said — yet, all the while, the 75-year-old former mayor, one of Trump’s personal lawyers, is spending $40,000 on his girlfriend’s son’s dental work and going to a Yankees-Red Sox game in London with his current gal pal.

Clair said that just 10 days after the divorce began, Rudy had dropped $50,000 on a private jet subscription service, which he once used to fly his girlfriend when he wasn’t even on the plane.

Clair said Giuliani told him in a deposition that he paid for the London trip with money he got from his podcast, which the lawyer says hasn’t even begun airing yet.

“That could be an issue at trial about whether he is or he is not purposefully lowering his income for the purpose of getting through this action,” Clair said.

Giuliani later hit back at the claims, telling The Post: “My reason for working for President Trump for free is wholly and entirely patriotic, and also because he is my friend.”

“In fact I started working for the president before we filed for divorce, so it has no bearing on my decision. I had decided to advise President Trump for free because I was outraged at how he was being very unfairly treated. I thought he was being framed by those with political agendas, and I was right,” he continued.

“I was angry and upset at the Mueller witch hunt, having worked so hard to get the president elected. I knew this was a plot conceived by bad people to remove him from office. I knew I could turn things around for President Trump, and I did.”

The couple’s case is expected to go to trial for a month in January.

In court, Giuliani’s lawyer, Faith Miller, said Rudy cannot support the lifestyle the couple used to have under his current salary.

“He doesn’t have it, and the burn rate to support Ms. Giuliani’s lifestyle and the court’s order is approximately $110,000 a month, net of taxes, before he buys himself a cup of coffee,” Miller said.

“He has made over $800,000, and every penny is going toward marital expenses,” Miller told the judge, noting that Giuliani pays Judith $42,000 in support payments monthly.

Miller also said that when Rudy moved back into the pair’s East 66th Street apartment, Judith, 64, had already stripped the place and left it messy.

“She took everything … china, silverware, everything off the walls,” Miller said, prompting an outburst from Judith, who slammed her hand on the table and shouted, “I did not!”

Clair told the judge that he wants an accounting of Rudy’s money since he claims to be financially struggling to the point he had to borrow $100,000 from one of Trump’s other lawyers, Marc Mukasey, and another $500,000 from another man.

Miller said, “Ms. Giuliani would have Mr. Giuliani work forever to support her lifestyle. She is a registered nurse” who refuses to work.

“There is no reason he should feel financial pressure at this stage in his life with the estate that he has amassed,” Miller added.

Miller also said Judith hadn’t paid $77,000 in fees on their Manhattan apartment and that when Giuliani moved back in May, he got a “termination notice.”

Outside court, Judith reiterated to reporters that she didn’t steal anything from their Upper East Side apartment.

“I was entitled to my family antiques, and he knew that,” she said, adding that her husband “kept all of my grandmother’s Christmas decorations,” while she has “some of the rugs. [And] things like that.”

Rudy later told reporters that he borrowed the money from Mukasey to pay taxes, since his money is locked up in the divorce. He said he had paid 90 percent of it back already.

When asked if Trump’s tax cuts had a negative impact on him he said, “They worked out really well for me — except my wife has tied up all my money.

“This has been going on now from April 4 of 2018 until today. You are talking about a $5 million account that I can’t have access to even though they are joint funds.”

Additional reporting by Emily Smith