The city reached a nearly $1 million settlement with a man who suffered a stroke after being falsely arrested in a landlord-tenant dispute, according to the comptroller’s office.

Gerardo Mayol’s $540 million lawsuit against the NYPD claimed cops at the 104th precinct in Ridgewood mocked him while in custody and refused to take him to a hospital when he became ill.

A cop even threatened Mayol if he urinated on the floor, telling him “he was going to use Mr. Mayol’s sweater to clean it up and then put his sweater back on him,” the lawsuit, filed in Brooklyn Federal Court, said.

Doctors later determined Mayol, a limo driver, suffered a stroke. He spent 20 days at Elmhurst Hospital due to the severity of his injuries.

The city settled with him for $988,000, the comptroller’s office said Wednesday.

In 2009, Mayol was arrested after trying to intervene in a fight between a neighbor Jessica Varney and the landlady of their apartment building.

He was expected to testify in eviction proceedings against Varney, who filed stalking and harassment charges against him.

Mayol — who alleged in his suit that Varney had a relationship with a sergeant at the 104th precinct — was arrested weeks later, spurring his NYPD nightmare.

Mayol’s attorney Joseph Tacopina said Mayol was “pleased” to have concluded the litigation.

“This settlement will drastically enhance Mr. Mayol’s life and pay for past and future medical expenses for permanent injuries that he suffered at the hands of the NYPD,” Tacopina said.

A city law department spokesperson said: “Settlement was in the best interest of the parties.”