The feds asked the NYPD to detain 179 illegal immigrants in the first four months of the year — more than double the total number for all of 2016 — but cops balked in each case, police officials said Monday.

“We have complied with zero federal detainer requests this year,’’ Police Commissioner James O’Neill said during a City Council budget hearing.

“We strongly feel that it is not the role of a municipal police force to enforce federal immigration laws.

“To turn our NYPD officers into de facto US Immigration and Custom Enforcement agents is to undo much of the highly commendable work we have achieved over the years,” O’Neill added.

NYPD Deputy Commissioner Larry Byrne said the feds’ number of detainer requests from January through April 30 under the Trump administration is more than double the 79 that the department received all of last year.

Mayor de Blasio has vowed to keep New York a “sanctuary city” for undocumented immigrants, meaning they will not be turned over to the feds for their illegal status if they have not been charged with a serious crime. In other words, the feds have to track down the illegals themselves if they want to try to deport them.

President Trump’s has threatened to withhold federal funding from sanctuary cities, but that move has been tied up in court.

US Attorney General Jeff Sessions said yesterday that the order will now “be applied solely to federal grants administered by the Department of Justice or the Department of Homeland Security, and not to other sources of federal funding.”

In late 2014, de Blasio signed into law a City Council bill that severely reduced the city’s cooperation with federal detainer requests. The city will turn over people with felony convictions within the prior five years, and only when the feds have a judicial warrant.

The city continues to cooperate on cases of possible matches with terrorist watch lists.

In the year before the law was passed — between Oct. 1, 2013, and Sept. 30, 2014 — the city transferred 2,016 detainees to the feds while not honoring 1,159 requests, according to city data.

The Department of Justice declined to address O’Neill’s remarks.