Mayor Eric Adams’ top aide at City Hall has submitted his resignation — and couldn’t help but take a dig at incoming lefty Mayor Zohran Mamdani, The Post has learned.

“While I told the press months ago that, ‘I will never work for a socialist,’ the mayor-elect’s transition team needlessly included me (and you) last week on a list of 179 City Hall staffers it intends to replace on January 1, 2026,” Deputy Mayor Randy Mastro said in a letter to Adams on Friday.

“No need to have done so,” Mastro wrote. “We will be leaving city government together.”

Deputy Mayor Randy Mastro is resigning, and says he wants no part of ‘socialist’ Zohran Mamdani’s City Hall. EMILY MARTINKA

Mastro, 69, who served as deputy mayor under Rudy Giuliani, was appointed to the same post by Adams in March after a slew of resignations over the mayors now quashed federal corruption case.

The ex-federal prosecutor has made no secret of his disdain for Mamdani’s social democratic leanings, and in particular has railed against the mayor-elect’s anti-Israel rhetoric.

In his resignation letter, Mastro thanked Adams for a second shot in city government.

“It is my understanding that I am the only person in modern city history to have served as top deputy and acting mayor in two different administrations — a distinction I will soon share with my successor in the incoming administration — proving there is still a place in city government for an elder statesman,” he said.

Zohran Mamadni included Randy Mastro in a list of City Hall staffers he intends to axe when he takes over as mayor. MediaPunch / BACKGRID

Mamdani announced last month that 74-year-old Dean Fuleihan, a former top aide for ex-Mayor Bill de Blasio, would take over the post when he takes office in January.

Mastro also heralded his nine months on the job under Adams.

“The time since [the appointment] has been a period of remarkable productivity, with crime down to record lows, jobs up to record highs, and affordable housing created at an unprecedented rate,” he wrote. “A true team effort, of which we can all be proud.”

In a statement Sunday, Adams shared the sentiment.

Mayor Eric Adams named Randy Mastro, a 69-year-old former Rudy Giuliani aide, as deputy mayor in March. EMILY MARTINKA

“I’m so glad Randy answered my call to return to City Hall after such a distinguished career in and out of government,” the mayor said. “His experience, wisdom, common sense and many contributions have been invaluable.

“As mayor, I often talk about landing the plane,” Adams added. “Over the past few months, Randy has landed enough planes to fill an airport.”

Reps for Mamdani did not immediately respond to a request for comment on Mastro’s dig.