But ever since Mr. Trump won his first round of primaries and his path toward the Republican presidential nomination became likelier, his family members and some supporters have urged him — not with a lot of success — to professionalize his performances, and to try to avoid the dangers of the kind of spontaneous remarks he made in Arizona.
There were obvious differences between the venue and audience for the Phoenix speech and those here on Wednesday. The first was a campaign-style rally for his most boisterous supporters, against a thumping soundtrack of the Rolling Stones; the second was an official presidential event for an audience of veterans, complete with a bill-signing ceremony.
There were many reasons to believe that the president’s angry performance in Phoenix was the real Donald J. Trump. It was consistent with the way he has reacted to all sorts of setbacks since he took office, including the Senate’s failure to repeal the Affordable Care Act and the multiple investigations of his links to Russia.
His advisers had actually anticipated the possibility that he would go off-script after The New York Times reported earlier Tuesday on his toxic relationship with Senator Mitch McConnell, Republican of Kentucky and the majority leader. The article was referred to frequently on the cable television shows that the president likes to watch.
While reporters declared his rally one of his most caustic in the past two years, some White House aides said privately on Wednesday that they found some comfort in the fact that it could have been worse.
Many presidents, of course, have complained bitterly behind closed doors about their treatment at the hands of the news media or their political opponents. Robert Dallek, a historian, said Franklin D. Roosevelt lashed out at the news media with his aides, while John F. Kennedy canceled a White House subscription to The New York Herald Tribune after a string of negative coverage.
“There was a difference between how they performed in public and private,” Mr. Dallek said.
The difference with Mr. Trump, he said, is that the president not only vents those feelings publicly, but also makes that venting a central part of his message.
In Phoenix, Mr. Trump did not so much depart from his prepared text as ball it up and toss it into a wastebasket. After speaking perfunctorily about the need for Americans to love one another — words borrowed from his somber, teleprompter-guided Afghanistan address to troops in Virginia on Monday night — Mr. Trump went off message. Placing blame on the news media, he delivered a discursive, defensive analysis of why he was not responsible for dividing Americans.
Mr. Trump threw in a few asides in his speech to the American Legion. Promoting legislation that he said would improve medical care for veterans and make the system more accountable, Mr. Trump promised that if the care did not improve, he would have one response to the people providing it: “You’re fired.”
He also elaborated on the Afghanistan strategy he unveiled Monday: “We will give our men and women in uniform the tools they need and the trust they have earned to fight and to win.”
And he promoted investments in missile defense, which he said would deter aggressive government overseas.
But for the most part, Mr. Trump’s focus remained on veterans.
He got a polite welcome from the audience at the Reno-Sparks Convention Center, though the group had made clear it did not share his ambivalent response to the clashes between neo-Nazis and white supremacists and counterprotesters in Charlottesville.
On Monday, the Legion reaffirmed a 1923 resolution condemning any individual or group that “creates, or fosters racial, religious or class strife among our people, or which takes into their own hands the enforcement of law, determination of guilt, or infliction of punishment.”
At the event, Mr. Trump signed into law bipartisan legislation that overhauls the federal government’s disability benefits appeals procedure for veterans.
About half a million veterans have pending claims contesting a Veterans Benefits Administration decision, many of which can take years to sort out. The new law is expected to substantially speed up that process by creating separate queues for veterans based on the evidence they wish to submit with their claims.
Mr. Trump also introduced a Medal of Honor winner, Donald E. Ballard, who declared that the president was the right leader to “drain the swamp.”
Mr. Trump laughed and said of Mr. Ballard’s impromptu remark: “That’s very risky of me. That could ruin the whole day for me.”
But in Mr. Trump’s view, it is the teleprompter — and any form of precanned remarks — that have long been the enemy. And it is true that his most memorable remarks have come without it.
When he launched his campaign in 2015, Mr. Trump almost instantly tossed aside his prepared speech, and instead went on a nearly hourlong riff about immigration, about the United States being taken advantage of and about Mexico not sending “their best” to the country.
“They’re bringing crime. They’re rapists,” Mr. Trump said, before adding that he assumed “some” Mexicans were “good people.”
When he brought on Paul Manafort as his campaign chairman in May 2016, one of Mr. Manafort’s first orders of business was to get the candidate to adjust to teleprompters. But when word leaked out that Mr. Manafort told a closed-door meeting of Republican National Committee donors that he was working on scaling back some of Mr. Trump’s more caustic remarks, the candidate publicly rebuffed those efforts.
“I sort of don’t like toning it down,” Mr. Trump told a crowd in Connecticut shortly afterward. “Isn’t it nice that I’m not one of these teleprompter guys?”