Two cabbies used an obscure law to score sweet apartments near the High Line for as little as $226 a month — even though similar-sized digs in the neighborhood go for around $3,200.

Hamidou Guira spent just one night in his new home in the Chelsea Highline ­Hotel before he was able to game the system with the help of fellow hack Joe ­Stevens and score himself a lifelong lease, according to sources.

Guira did it by submitting a written request to become a permanent tenant under a little-known section of the Rent Stabilization and New York City ­Administrative codes.

Because the hotel at 184 11th Ave. is a former SRO, “an occupant who requests a lease of six months or more . . . shall be a permanent tenant,” the law says.

The owner must accept the lease at the regulated rate — $226 — and it can be renewed indefinitely.

In Guira’s case, the hotel manager tried “forcefully preventing” him from entering his room on July 31 after learning of his plan.

But the cabby went to Manhattan Housing Court and, acting as his own lawyer, won the case when Justice Sabrina Kraus ruled he was “unlawfully evicted” from his dirt-cheap digs.

“It’s one of those things that is just so strange,” said Joe Restuccia, executive director of the nonprofit Clinton Housing Development Corp.

Restuccia’s group is partnering with the owners of the hotel to turn the building into 15 units of ­affordable housing with apartments starting at $800 a month.

“That part of the law means that at any hotel in the city, [you] can claim a need for relief like at The Waldorf and the Marriott Marquis. It applies to everybody, but it’s fallen out of use,” Restuccia said.

Restuccia said Guira ­received guidance from Stevens, another longtime resident, who learned to navigate the back roads of the housing law when he successfully fought the building’s former owner over harassment.

Restuccia said Stevens likely drafted court papers for Guira, who needed a French interpreter to try his case in Housing Court.

When reached by The Post, however, Stevens denied he gave any legal advice to Guira, who declined to comment. Stevens did say he steers people to ­low-cost housing.