Federal agents arrested an immigrant who is in the U.S. illegally after a North Carolina sheriff declined their request to keep the registered sex offender in custody, immigration officials said Wednesday.

U.S. Immigration and Customs Enforcement said Raleigh-based agents arrested Udiel Aguilar-Castellanos at his Carrboro, North Carolina, residence Monday morning. ICE discovered he was a sex offender when he registered with Orange County on July 11. The 44-year-old Mexican national is being held at the Stewart Detention Center in Lumpkin, Georgia.

On June 27, Aguilar-Castellanos pleaded guilty to two counts of sexual battery of an 11-year-old girl and was released the same day under the condition that he register as a sex offender. Prior to his guilty plea and release, he spent nearly 300 days in the custody of local officials. The public defender assigned to his case was not available for comment Wednesday afternoon.

According to a release from ICE, Aguilar-Castellanos first received a final order of removal from a federal immigration judge in January 2015, and avoided deportation for more than three years. He was convicted of DWI in 2014.

ICE, which was notified of Aguilar-Castellanos' arrest in September 2017, says the Orange County Sheriff's Office refused to honor an immigration detainer the agency filed at that time. The agency uses detainers to request local law enforcement to hold a person in the U.S. illegally for longer than 48 hours so federal authorities can take them into custody.

The Sheriff's Department said in a press release Wednesday that an official with their department had contacted ICE by phone to notify the agency of Aguilar-Castellanos' release, but did not receive a response. The sheriff's department also challenged the validity of immigration detainers, calling them insufficient cause to hold someone in custody, as they are not issued by a judge.

Sheriff Charles Blackwood has in the past told local media his office does not honor immigration detainers from ICE, citing concerns about potential civil rights lawsuits.

Doubts about the legality of honoring detainers are shared by Orange County Latino advocacy groups. Eliazar Posada from El Centro Hispano called the extended detainments "constitutionally murky," and challenged the ICE criticism of local law enforcement. "It's not the sheriff's job to do the job of federal agents," Posada said.

A spokesman for ICE said another sex offender in the U.S. illegally was released by the Orange County Sheriff's department almost two months ago under similar circumstances to Aguilar-Castellanos. In May, 19-year-old Guatemalan national, Jonathan Gudiel Escobedo, pleaded guilty to sexual battery of a 14-year-old. An ICE spokesman said he was re-arrested in June and deported back to Guatemala.