The New Yorker Hotel is locked in a court battle with a man it says is a shameless freeloader who scored a year rent-free under an obscure legal loophole — and then filed a phony deed to commandeer the entire Midtown building.

Now the real owners of the 43-story structure topped with the iconic New Yorker sign are scrambling to get Mickey Barreto’s alleged fraud reversed.

Barreto, 44, spent one night in the historic Art Deco hotel in June 2018. The next day he asked for a six-month lease under an obscure section of the rent-stabilization laws, according to court papers filed in Manhattan Supreme court.

The hotel declined, locking Barreto out — but he ran to housing court, where a month later, Judge Jack Stoller ordered the hotel to let Barreto back in.

But that wasn’t enough for Barreto, who somehow convinced clerks at the city Department of Finance that the paperwork gave him not just a room, but ownership of the whole building.

Barreto’s deed, which he filed May 28, lists the building as a “religious structure” and claims his “purchase was by court order” at a whopping price of $189,336,000.

He now purports to run “Mickey Barreto Missions” out of 481 Eighth Ave; has demanded rent from two restaurant tenants; called hotel operator Wyndham trying to “take over hotel operations;” attempted to get the building’s bank accounts transferred to him; and summoned the FDNY, demanding an evacuation because of a nonexistent gas leak, Manhattan Supreme Court papers show.

He cheekily requested a $15 million payment from the building’s true owners, noting, “I will gladly take cash or check.”

Then he posted on a since removed LinkedIn page, “I OWN the building where the New Yorker Hotel is located in Manhattan. ALL MINE!!! Please apply here for your section 8 apartment in Manhattan.”

The Holy Spirit Association for the Unification of World Christianity has owned the New Yorker hotel since 1976.

The Association fears Barreto could take out a lien or mortgage on the building or try to sell it “to an innocent third party.”

The city Finance Department, which says only a court can void a bad deed, gets 40 new deed fraud complaints each month.

A Manhattan Supreme Court judge called Barreto’s ownership bid “bizarre” and said it was “abundantly clear” Barreto is not the owner — but only ordered Barreto to remove public references to himself as the owner.

Barreto defended his actions to The Post: “I never committed any fraud,” he insisted.