WASHINGTON — President Trump condemned the deadly newsroom shooting in Maryland, declaring on Friday that “journalists, like all Americans, should be free from the fear of being violently attacked while doing their jobs.”

Mr. Trump has labeled the news media “the enemy of the people” and routinely encourages supporters at his rallies to join in his verbal attacks against the journalists covering him.

On Friday, however, he chose the standard vocabulary of a political leader offering condolences. “This attack shocked the conscience of our nation and filled our hearts with grief,” he said.

Speaking at a White House event to celebrate his tax cuts, Mr. Trump, in brief remarks, expressed his “warmest, best wishes and regrets” to families of the five people killed by a gunman who shot his way into the newsroom of The Capital Gazette in Annapolis, a local newspaper on Maryland’s shore.