President Trump’s admonition that the police should not be “too nice” while transporting suspects drew laughter and cheers from a crowd of officers on Friday, but police officials swiftly made it clear they did not find the words funny.

From New York to Los Angeles, law enforcement authorities criticized the president’s remarks. Experts worried that his words could encourage the inappropriate use of force. A defense lawyer even signaled that he might use video of the speech in court.

The criticism online started shortly after Mr. Trump’s comments, which came at an event in Brentwood, N.Y., which was intended to support the police in their fight against La Mara Salvatrucha, or MS-13, a gang that has been accused of several murders on Long Island.

After calling for more immigration officers to help arrest the gang members, Mr. Trump told officers, “Please don’t be too nice.”