It took a federal judge to reign in Gov. Andrew Cuomo’s fiercest strikes against his good government critics, ending a three-year court battle over a state law that would have required the watchdog groups to disclose their donors.

Manhattan federal court Judge Denise Cote sided with a coalition of government watchdog groups last week, ruling that the Cuomo-backed measure from 2016 would have a “chilling effect” on free speech and “places a significant burden on the First Amendment.”

“This state law targeted not-for-profit ‘good government’ groups for having the temerity to raise ethics issues and try to get the government to do better. It’s blatantly unconstitutional,” said lawyer and Citizens Union board member Randy Mastro.

The law’s requirements forcing nonprofits like Mastro’s to disclose their donor’s identities was never enforced because of the federal litigation.

“The mere threat that it could happen — even if nobody pulls the trigger — chills free speech,” argued Blair Horner, a former Cuomo aide who now runs the New York Public Interest Research Group. “Is this about power? Crushing dissent by creating, at best, difficult things to deal with for nonprofits?”

Cuomo announced the bill at the tail end of the 2016 legislative session, claiming it would close loopholes created by the 2010 US Supreme Court decision in the Citizens United case that loosened rules on outside groups participating in politics.

“The legislation also would strengthen disclosure requirements and mandate that groups report the identity of anyone exerting control over them,” Cuomo said at the time.

The governor introduced the measure as good government groups assailed him and his inner circle over a series of ethics scandals that would eventually put two of his longtime aides in jail: former right-hand man, Joe Percoco; and Alain Kaloyeros, who headed the state’s controversial $1 billion program to reboot Buffalo’s economy.

The bill was introduced in the pre-dawn hours of the last day of the 2016 session, circumventing rules that would typically prevent such a maneuver because Cuomo blessed it with a “message of necessity.”

“On the face, I have serious concerns … because I think it’s too rushed,” Democrat state Sen. Diane Savino (D-Staten Island) declared on the chamber floor, before voting “no.”

The legislation passed the Assembly unanimously, and with just one other dissenting vote in the Senate — from then-Democratic state Sen. Marc Panepinto.

Experts quickly pointed out the bill would hit good government groups the hardest and they quickly sued.

Cuomo fired another salvo when he attempted to lower the lobbying spending limit from $5,000 to $500 in his 2019 budget proposal, a move that would’ve hit the good government groups the hardest. The measure was ultimately dropped.

On occasion, the enmity Cuomo and his top advisors feel seeps out from Albany’s backrooms and explodes in public view.

Cuomo’s enforcer on the MTA board, Larry Schwartz, berated a staffer from Reinvent Albany during the public comment period as she spoke about press accounts detailing the overlap between then-MTA chairman Joe Lhota’s business interest and governing responsibilities.

“Do not start accusing him, or anyone else on this board of pay-to-play or conflicts of interest, especially when you don’t know your facts, and your facts are totally wrong,” Schwartz screamed at the staffer, Rachael Fauss, in March 2018.

Lhota was later forced to resign because of the conflicts of interest.

“All their arguments smack of rank hypocrisy,” said Rich Azzopardi, senior Cuomo adviser, who said the state was considering an appeal. “Everyone preaches transparency until transparency shows up on their own front door.”

Azzopardi added: “What is the advocacy industrial complex hiding?”