Six Long Island cops claim their commissioner is putting politics before the badge.

The Long Beach crime fighters say they’ve been targeted by the seaside town’s Democratic machine for supporting GOP candidates in local elections last year.

Long Beach Police Commissioner Michael Tangney, a longtime Democrat, demoted the cops, cut their overtime, switched them to midnight tours and even filed false internal charges against them for “political payback,” the veteran officers claim in a $39 million lawsuit.

“It’s just the way politics work in this town,” Tangney allegedly told one of the officers while demoting him.

Officers James Canner, 44; Karl Hayes, 42; James McCormack, 55; John Radin, 53; Benjamin Tayne, 47; and Jose Miguez, 39, claim they turned to their union for help, but that then-president Stefan Chernaski, another Democrat, ignored them.

Chernaski filed his own $27.5 million claim last year against a then-Republican administration, claiming harassment. He settled for $25,000, and got two promotions and a $20,000 pay hike when the Dems swooped into power.

Chernaski had never worked as a detective, yet was put in charge of the detective division, bumping aside Canner, a decorated officer who supported the Republican opponent of Tangney’s wife, Darlene, in her Nassau County Legislative race last year.

When Hayes learned of his January demotion from supervisor of investigators to sergeant, he “began crying hysterically for three to five minutes,” according to Brooklyn federal court papers. The stress of the demotions and suddenly being put on the midnight shift caused McCormack, a lieutenant who headed the traffic division, to retire, the suit alleges.

Radin, demoted from inspector to lieutenant, saw his monthly pay slashed from $18,000 to about $10,000, and he was moved to a small cubicle and referred to as “Jack in the Box,” according to court papers.

All of the officers involved, including Tangney and Chernaski, earned well over $130,000 salaries last year, according to See Through NY.

The town’s Democratic Party boss Michael Zapson sneered, “The fact that the gravy train is over for them, I’m not surprised they’re upset.”

Eric Rothstein, lawyer for the six officers, said the raises Tangney and Chernaski received offset any saving the city got by slashing his clients’ pay. “Politics doesn’t belong in the police department,” he said.

Former City Council President Jim Hennessy, a critic of City Manager Jack Schnirman’s government, slammed the Democrats as power mad.

“Everything is politics. It’s not about government,” he said. “It’s about getting power, holding power, keeping power, and going to town against anyone who threatens that power.”

The city and the PBA have denied the allegations as “false” and “frivolous,” and said they would aggressively defend themselves against the lawsuit.