Bob Madison thought he might face sneers from opponents of gentrification when he and his husband bought a Harlem brownstone six years ago — but he didn’t expect to be tossed in jail.

The p.r. exec and his spouse, both white, have announced plans to sue the city for $5 million, claiming Madison was falsely arrested on a fabricated hate-crime allegation after a quarrel with a politically connected state employee.

“This is a blatant case of [someone] using the legal system, with the help of his political, Police Department and district-attorney connections, to persecute Bob Madison, an innocent man,” said Madison’s attorney, Robert Sharron.

Madison had clashed with Willie Walker, a black Harlem resident, on Nov. 28, 2012, in front of the couple’s West 126th Street building.

Walker, a former community-board chair and one-time City Council candidate, is the superintendent for the Adam Clayton Powell State Office Building, located behind the home.

Madison and his husband, Russell Frost, claim Walker flew into a rage when the men complained that his workers had dumped debris in front of their building.

Madison said Walker told him, “I’m tired of your s- -t, motherf- -ker.”

Madison admitted to asking Walker, who wears African garb, “Why do you go to work in your pajamas?”

Walker replied, “You f- - - -ts should move out of Harlem,” according to a complaint Madison phoned in to the man’s boss that day.

The boss, Chuck Gianatasio, director of labor relations for the Office of General Services, promised to look into the complaint. But the next day, cops charged Madison with a hate crime.

Walker had claimed Madison said, “I can kill all you n- - -as,” while “flailing his arms in a monkey-like manner,” according to a complaint obtained by The Post.

Madison, who has no criminal record, was held in the Manhattan Detention Complex downtown for 32 hours with teens who had been busted for slashing people with straight razors.

“It was like being in ‘Dante’s Inferno,’ ” he said.

The couple says the District Attorney’s Office dragged the case out for months, dropping it only when the one-year limit was reached.

Madison and Frost filed their intent to sue the city with the Comptroller’s Office last year, claiming the NYPD had known Walker’s allegations to be false.

A city Law Department spokesman said that he was aware of the claim and that it would be reviewed.

Walker did not return calls for comment.

A spokeswoman for Gianastasio refused to comment.