Federal authorities criticized Philadephia's "sanctuary city" polices on Thurday after announcing that they nabbed an undocumented immigrant who was convicted of a sex crime and released after serving his prison term.

Milton Berrera-Lopez, 29, of Guatemala, was apprehended a week after being released from “local custody” on Aug. 30, U.S. Immigration and Customs Enforcement (ICE) said.

Berrera-Lopez was released after spending about two years in custody for two counts of indecent exposure involving minors. Berrera-Lopez was convicted on Aug. 30, and was sentenced to two years in prison, two years’ probation and forbidden from contacting minors. Since he already served the time, he was released.

RELATED: State rep.: I was 'ambushed' by immigration activists

ICE filed a detainer to request a Philly city jail hold on Berrera-Lopez so they could take him into custody for violating U.S. immigration law, but the jail released him, ICE said.

Federal agents arrested Berrera-Lopez later that same day when he went to report to his probation officer at a center in Montgomery County, and is now in federal custody pending deportation proceedings, ICE said. 

In a news release announcing the arrest, an ICE official called out Philly’s sanctuary city policy, stating that it is “creating a potentially unsafe environment for the city’s residents."

“When convicted criminal aliens who pose a threat to children are released into communities instead of being safely transferred to ICE custody in a secure environment, our communities are exposed to an unnecessary risk,” said Thomas Decker, director of ICE’s Philadelphia Enforcement and Removal Operations in a statement.

He went on to urge the city to change it’s policy. “This level of risk can be mitigated in many instances … the agency welcomes significant modifications to the current policy which is creating a potentially unsafe environment for the city’s residents." 

But Mayor Jim Kenney's spokeswoman Lauren Hitt rejected that criticism.

"It’s completely inaccurate to say our policies put Philadelphia in danger. It’s just the opposite," Hitt said via email. "By not making our police and prisons do ICE’s job for them, we have stronger relationships with our immigrant communities. In cities without sanctuary city policies, immigrants are often too scared to report crimes or act as witnesses in criminal cases."

ICE issues detainer “holds” to local law enforcement when they have a person in custody whose immigration status is in question. ICE asks that the person be held until federal agents can take them into custody.

RELATED: Toomey beats anti-sanctuary city drum as re-election campaign heats up

Philadelphia rejected cooperating with these “holds” and adopted a “sanctuary city” policy in 2014 when Mayor Michael Nutter signed an executive order ending city-ICE cooperation.

The sanctuary city policy has been strongly defended by Mayor Kenney, even as it has earned him plenty of heat, including from politicians around the state and in Washington D.C.

U.S. Sen Pat Toomey (R-Pennsylvania), who is running to keep his seat against Democratic challenger Kate McGinty, said the Berrera-Lopez case proves her wrong in her support for Philly’s sanctuary city policies.

"The constant failure of these sanctuary city policies only underscores how out of touch Katie McGinty's extreme liberal agenda is with Pennsylvania families and communities,” Toomey for Senate spokesman Ted Kwong said in a statement.

Hitt said that Philly authorities would cooperate if ICE presented a warrant for the person they are seeking, and noted that ultimately, ICE was able to arrest Berrera-Lopez on their own.

"This arrest is proof that ICE doesn’t need to rely on our prison system to do their job," Hitt said. "They clearly have other tools in their arsenal to go after individuals they seek."

ICE said it removed or returned 235,413 individuals in 2015, 98 percent of whom were "priority" cases, with 86 percent of those people falling into “Priority 1,” which denotes “aliens who pose a danger to national security or a risk to public safety,” such as violent criminals, felons, repeat offenders, criminals subject to outstanding warrants and gang members.