Several times in recent months, the federal government has attacked Middlesex County for releasing unauthorized immigrants from jail even when they are convicted of terrible crimes, like sexual abuse of children.

If the charge were true, it would indeed be outrageous. These are the first people who should be deported. On that much, at least, most Democrats and Republicans can agree.

But it is not true. It is a terrible slander of Middlesex County. The fault, in fact, often lies with the U.S. Immigration and Customs Enforcement agency itself, which blew opportunities to deport some of the very people it is citing in its unfair attacks on Middlesex.

The fact that the Trump administration is using these phony charges as justification for cutting public safety grants only compounds the sin.

Take the case of a 32-year-old sex offender from Mexico, arrested in 2016. ICE put a detainer on him then - a request for the jail to hold him for up to 48 hours extra, while immigration officials decide if they want to take him into custody. The jail agreed to this. Yet ICE never picked him up. Instead, the guy sat behind bars for nearly two years, awaiting trial.

ICE says people should be held accountable for their crimes before they get deported. We agree. But ICE had two years to get a judicial order requiring this man to be detained after his sentence was completed, until it could pick him up. And it did nothing.

In May, he pled down to a lesser charge and was sentenced to time served. The county notified ICE that the detainer would no longer be honored, because it's against jail policy to hold inmates convicted of lesser crimes past the final date of their sentence.

But ICE never responded and never took him into custody. He was let out 24 hours later.

Then ICE issued a scathing news release, citing this case and slamming Middlesex for being a "sanctuary." Please. How is it not ICE's fault that he was released?

At the core of this debate with ICE is the detainer, which is basically a request to hold inmates after they have completed their sentences. The problem is that while ICE demands that, the courts have repeatedly found that the practice violates inmates' due process rights. So, if Middlesex obeyed ICE, the county might have to pay big settlements, funded by property taxes.

Middlesex has agreed to take that risk with the most serious criminals. But ICE hasn't done its part by getting federal court orders to authorize that added time in detention. Instead, ICE rants at the county jails and blames them.

Yes, Middlesex should be better at communication and not so absolutist in its stance that it can't help ICE in any way. Its jail already holds people beyond their release date when they're convicted of the worst crimes, despite the liability.

It should routinely give ICE a heads up in situations like this sex offender, who pled down from serious charges and was about to get out, or anyone convicted not just of higher level crimes, but also a serious third-degree offense, like aggravated assault. A phone call 24 hours ahead of time does not hold the same legal risk as a detainer.

But what ICE has been saying about Middlesex amounts to a defamatory smear. And this is not the only example. ICE also unfairly blamed the county for releasing a man from Honduras accused of sexually abusing a minor, when its own agents never picked him up.

He arrived at the jail on Dec. 1, 2017, having been sentenced to a lesser charge. The ICE detainer came in Dec. 4 and the jail rejected it the same day. Yet he remained in the lock-up until Feb. 23rd. So, again, why didn't ICE come for him?

Based on cases like these, the Trump administration says it will punish Middlesex and other so-called "sanctuary" counties, by withholding hundreds of thousands of dollars in annual policing grants.

This goes directly to the heart of public safety. It's money to help enforce Megan's Law and fund our SWAT teams that battle gun and gang violence. By imposing this penalty, it is the Trump administration putting public safety at risk, not Middlesex.

A better solution is for ICE to actually show up before these guys get out of jail. If it doesn't have the capacity, maybe it should reallocate some resources from its amped-up arrests of grandpas with no criminal records.

Rather than sit back and call this county a "sanctuary," why not take a drive over to Middlesex to pick up a sex offender?

Bookmark NJ.com/Opinion. Follow on Twitter @NJ_Opinion and find NJ.com Opinion on Facebook.