Over the years, there have been few more vocal or aggressive advocates for law enforcement than Rudolph W. Giuliani. A former top official at the Justice Department, a onetime prosecutor with a tough, crusading style, and a police-embracing mayor who ran New York on a law-and-order platform, Mr. Giuliani — both in office and as a private citizen — has spent the better part of his career stridently defending the country’s crime-fighting class and fiercely lashing out at those who attack it.

But in his latest role as a lawyer for President Trump, Mr. Giuliani (who, like his client, is volatile by nature) appears to have made an abrupt change of course. In the past few days, he has launched a series of rants in the media, assailing his former colleagues in law enforcement — and the work that they have done — as Nazis, frauds and garbage. And in a phone interview Friday, he defended the strong criticism he had made.

While the path from prosecutor to defense lawyer is a common one that often requires a sharp shift in perspective, several former law-enforcement officials said they found it curious that Mr. Giuliani had so quickly and belligerently turned his back on a world he had worked in for nearly 30 years. Even some who expressed support for him said that his assaults on everyone and everything from the Russia investigation to James B. Comey, the former director of the F.B.I., to the bureau’s New York office, seemed to be out of character.

“It’s astonishing, especially from someone who has been so supportive of law enforcement for as long as he has,” said Asha Rangappa, a former F.B.I. agent who now works as a TV analyst and a senior lecturer at Yale University. “I can’t believe that anyone believes that he really believes what he’s been saying. But it’s a standard defense counsel playbook. When you don’t have the facts on your side, you attack the investigators.”