A Manhattan man who long ago transformed an unlivable Tribeca loft into apartments owes nearly $1 million for squatting, the landlord claims.

Stephen Grant and a girlfriend moved into 329 Greenwich St. in the 1970s, when the fourth floor “didn’t have a toilet. It didn’t have electricity or a kitchen. It was a raw space,” he told The Post.

He laid the maple flooring and put up the ceilings himself. Grant and his then-girlfriend created a front and a rear apartment in the loft, sharing the $600 rent.

By 2002 his ex had moved to Italy and Grant, by then a married father of three, co-opted her rear unit, taking the entire floor for himself, court papers show.

Landlord SMCB Associates accused Grant of trespassing, and fought for 15 years to evict Grant and his family from the second unit.

They succeeded in 2015 and now claim Grant owes $905,000 — or $5,000 a month — for the years he spent using the second unit without SMCB’s permission.

Grant, who still lives in the front unit with his family for just $400 a month, claimed the landlord had never compensated him for the work he did in the building.