The legislation, known as the Laken Riley Act, is the first to be signed by the president in his new term, and shows how the politics of immigration have shifted.

President Trump signed a bill on Wednesday to require the detention of migrants who enter the country without authorization and are arrested or charged with certain crimes, the first legislation of his new presidency and an early victory in his effort to deliver a sweeping crackdown on immigration.

The new Republican-controlled Congress passed the legislation last week with some breakaway Democratic support, a sign of how the politics of immigration have moved to the right. Mr. Trump has long made curtailing immigration a centerpiece of his political identity, and the signing of the bill came after a flurry of executive orders that sought to systematically limit both legal and illegal entries into the United States.

It’s a landmark law that we’re doing today,” Mr. Trump said in remarks at the White House before the signing. “It’s going to save countless innocent American lives.”

The legislation, called the Laken Riley Act, is named for a 22-year-old Georgia nursing student killed last year by a migrant from Venezuela who had crossed into the United States illegally. The man had previously been arrested in a shoplifting case but had not been detained.

While the crimes have gained national attention, Mr. Trump has a long history of inflating immigrants’ criminality, and homeland security officials working across both Democratic and Republican administrations have acknowledged that most migrants crossing the border are fleeing poverty or persecution. For the past 150 years, immigrants overall have been less likely to commit crimes than people born in the United States, a 2023 study concluded.

The bill expands the list of charges that will subject migrants to immediate detention and potential deportation, instructing federal officials to detain unauthorized immigrants arrested in connection with or charged with burglary, theft, larceny, shoplifting, assaulting a police officer, or crimes that result in death or serious bodily injury.

It will also empower state attorneys general to sue the U.S. attorney general or the homeland security secretary if an immigrant who has entered the country illegally commits a crime that harms the state or any of its residents.