Tension over illegal immigration in Massachusetts spiked on Tuesday after one Democratic lawmaker warned her city about a potential federal raid and Bristol County Sheriff Thomas Hodgson went before Congress and said elected officials in “sanctuary cities” should be arrested.

The rhetorically charged debate that played out in a hearing room on Capitol Hill and on social media came a day after Attorney General Jeff Sessions said communities would have to prove compliance with federal immigration law to be eligible for funding through the Justice Department.

The Department of Homeland Security recently listed Boston, Cambridge, Somerville, Northampton, and Amherst as cities that have enacted policies limiting cooperation with Immigration and Customs Enforcement (ICE).

Hodgson, a Republican who once offered to send county jail inmates to help build President Donald Trump’s southern border wall, testified before the House Judiciary Subcommittee on Immigration and Border Security.

Hodgson told the federal panel that he saw “no bigger threat to public safety” than illegal immigration, and he said elected leaders of so-called sanctuary cities were at worst committing a “careless, illegal and extremely dangerous” act.

The sheriff also told the Congressional panel about a state representative from Plymouth County who had used Facebook to alert people to the possibility of an ICE raid this week in Brockton.

“This is the most outrageous, outrageous thing or example of what is going on across the United States,” Hodgson said. “It’s undermining my job and every other law enforcement officer in the United States to keep our communities safe and that elected official whose responsibility for protecting the welfare of the people of their communities needs to understand that they could be protecting someone that ICE is looking for that may be possibly connected to terrorism, transnational gangs or some other horrific criminal history that they’ve had.”

Hodgson was referring to state Rep. Michelle DuBois, a Brockton Democrat who posted on Facebook that a friend of hers in the “Latin Community” had alerted her to possible ICE raids on Tuesday and Wednesday in the city.

She also posted what appeared to be advice from her friend for undocumented immigrants, recommending they avoid going out on the street and not answer the door for anyone they don’t know.

Somerville Mayor Joseph Curtatone, whose city considers itself a sanctuary city, blasted Hodgson on Twitter. Curtatone has defended his city’s policies toward immigration, arguing that local police have succeeded in reducing crime without eroding trust between law enforcement and immigrant communities.

“Oh no, MA’s Joe Arpaio wannabe is spouting nonsense again. Last time he was offering Trump slave labor. #mapoli #SanctuaryCity,” Curtatone posted to Twitter, referring to the outspoken and conservative former sheriff of Maricopa County in Arizona.

Curtatone then proceeded to get involved in a nasty back-and-forth with WEEI radio host John Dennis, who backed up Hodgson and singled out the Somerville mayor as a “left wing whackjob” who should be the first put into handcuffs.

“I guess blowhards gotta blowhard,” Curtatone wrote back in a string of messages.