It doesn’t pay to be a rat.

A shady Queen businessman was sentenced Friday to two years behind bars for running a mortgage-fraud scam, after cooperating with authorities and rolling over on former state Sen. John Sampson.

Edul Ahmad, ex-associate of Sampson and Queens Congressman Gregory Meeks, had been under the impression that he’d be getting by with a slap on the wrist, seeing how he wore a wire during a sit-down with the senator at a Queens restaurant in 2012.

Sampson was later convicted of obstruction of justice for taking part in the $3 million scheme.

But Brooklyn federal Judge Dora Irizarry apparently felt Ahmad’s role in the scam was one that should not go ignored and instead chose to teach him a lesson.

She said that simply the fact that he cooperated “to me that doesn’t show remorse.

“What it shows is someone who is ready to do what he needs to do. Laws be damned, rules be damned.”

During a meeting in 2006, Ahmad wrote Sampson — a powerful Brooklyn Democrat at the time — a check for $188,500 to help him deal with ongoing legal problems.

The politician paid him back with political favors, and Ahmad was later arrested for mortgage fraud.

He eventually flipped to help snare Sampson, thinking he could dodge jail.

But instead of getting probation as his lawyer said he expected, Ahmad was sentenced to the two years. Still, it is a lot less than the six- to seven-year punishment he could have received had he not helped police or pleaded guilty.

The 50-year-old insisted Friday that he thought at the time that he did nothing wrong, telling the judge, “I really didn’t know I was committing a crime.”

Irizarry retorted, “I find that hard to believe. You knew when the gig was up…and you knew it was going to come out.”

Ahmad replied, “It was a lapse in judgment…[I am] truly sorry your Honor, and I promise you that you will never see me in this courtroom ever, ever again.”