He said that prosecuting immigrants who had entered the country illegally and committed crimes was still the federal government’s priority, and that the government was not “out seeking witnesses to crimes to deport.” But he added, “It cannot be that the attorney general grants immunity contrary to law for people who violate the laws of the United States.”

Mr. Sessions then met with law enforcement officials from Suffolk County, Nassau County and the State Police to discuss ways to best fight a gang whose hallmark weapon is the machete.

Before Mr. Sessions arrived, about 200 protesters gathered in the early morning outside the courthouse, across the lawn from the armored cars and Homeland Security guards.

“I’m concerned that his response is anti-immigrant, which would lead to racial profiling Latinos, African-Americans,” said the Rev. Calvin O. Butts III, the president of the State University of New York at Old Westbury.

But Representative Peter T. King, a Republican from the Second District of New York, which includes Central Islip and neighboring Brentwood, was visibly angered by the protesters. He had invited Mr. Sessions to Long Island to meet with law enforcement officials to help solve the problem, and attended a news conference after Mr. Sessions’s speech.

“They should be on their knees thanking him, not out there protesting,” Mr. King said at the news conference. “It’s shameful, it’s disgraceful that leaders in the community would criticize the attorney general.”

Mr. Sessions said the first step to combating criminal groups like MS-13 was to secure the border and restore “a lawful system of immigration.” He noted that the administration was adding immigration judges at the border to expedite deportations, and criticized the “lawless practice” of sanctuary cities that do not cooperate with immigration authorities. (Though, in a reversal, he said that he was “a big admirer” of the New York Police Department for leading the way in community-based procedures, and proving that “broken-windows strategies work,” referring to aggressively policing minor violations to prevent more serious crimes.)