Michael Grimm, a former New York congressman and FBI agent who once investigated white-collar crime, was sentenced Friday to 8 months in prison for tax evasion by a judge who said his “moral compass” needed adjustment.

Grimm, 45, pleaded guilty late last year to aiding in filing a false tax return — a charge that stemmed from an investigation into the Staten Island Republican’s campaign financing.

U.S. District Judge Pamela Chen said the crime included exploiting immigrant laborers, including some who were paid as little as $4.60 an hour.

RELATED: DA wins NYC special election to fill congressional seat

“He knew what he was doing was illegal, wrong and criminally punishable,” she said. Grimm, “of all people, knew better.”

“Your moral compass, Mr. Grimm, needs some reorientation,” the judge told him.

“I want to apologize to the court for even being here,” said Grimm, adding that he had cheated on taxes to keep a business afloat.

“I didn’t want to fail and I made bad decisions that I’ll regret for the rest of my life,” he said, prompting the judge to criticize his “belated remorse.”

Prosecutors had sought at least 2 years behind bars.

Prosecutors said the tax fraud began in 2007 after Grimm retired from the FBI and began investing in a Manhattan eatery called Healthalicious. An indictment accused him of underreporting more than $1 million in wages and receipts to evade payroll, income and sales taxes, in part by paying immigrant workers, some of them in the country illegally, in cash.

Grimm got to Congress by scoring an upset win over first-term Democratic Rep. Michael McMahon in 2010. He won re-election in November while fighting the charges but later resigned.

In court papers asking for a sentence of probation, defense lawyers called Grimm’s offense “an aberration in an otherwise remarkable life in selfless service of his country,” including a stint in the Marine Corps. They also argued that losing his career in Congress was punishment enough.

Grimm “is anguished over his wrongdoing and will live with the shame of it the rest of his life,” the defense said.

The government cited a news conference last year outside the Brooklyn courthouse where Grimm called the case “a political witch hunt.” It also referred to an episode in which Grimm threatened to throw a local cable TV news reporter off the balcony of the capitol for asking about the campaign financing inquiry.

He is scheduled to surrender on Sept. 10.