CEDAR RAPIDS, Iowa — President Trump said on Wednesday that he was crafting legislation to bar new immigrants from receiving welfare for at least five years. He announced the proposal in a conquering-hero-returns speech in Iowa, his first trip back to the political battleground state since he won it in the 2016 general election.

His mood buoyant after twin Republican wins in congressional special elections the night before, the president also revealed his anticipated plan for putting solar panels on a proposed wall on the Mexican border — an idea he boasted he had come up with himself.

And he — mostly — managed to avoid raising the topic he struggles to stop talking about: the investigations of Russian meddling in the 2016 election and possible collusion with his campaign.

The Run-Up

The podcast that makes sense of the most delirious stretch of the 2016 campaign.

“They have phony witch hunts going against me,” Mr. Trump said nearly an hour into a speech that veered off script repeatedly. “All we do is win, win, win. We won last night.”

The rally, Mr. Trump’s first since the end of April, served as a venting session for a pent-up president who has stewed and brooded from inside the gilded cage of the White House over attacks from investigators, Democrats and the news media, his interview schedule drastically pared down and his aides imploring him to stay off Twitter.

Style-heavy and substance-light, the speech went over an hour: an epic version of the fact-challenged, meandering and, even for his detractors, mesmerizing speeches he gave during his upstart presidential campaign.

Mr. Trump gave few details about his plan for the solar panels, beyond that it creates “energy and pays for itself,” or about his coming proposal to greatly curtail welfare for new immigrants — including how it would differ from existing laws that do just that. He called it a “total rewrite of our immigration system into a merit-based system,” words consistent with the public tone he has struck on immigration restrictions.

The president, whose approval rating is mired below 40 percent, told the crowd of roughly 6,000 people at the U.S. Cellular Center that he was thrilled to be out of the “Washington swamp.”

He barely reacted to whistle-blowing protesters who interrupted him within the first five minutes of the speech, when he was honoring Representative Steve Scalise, the Republican House whip, who was shot during a baseball practice last week and now faces a long rehabilitation. “Never fails,” Mr. Trump said as the protesters were led out.

Free from his handlers for roughly 70 minutes, Mr. Trump described his administration as he wished it to be: one in which he had made historic governing accomplishments and been stymied solely by the “resistance.”

“I think health care is going to happen, and infrastructure is going to happen, and I look forward to being able to produce it,” he said.

He derided trade deals despite an Iowa economy that relies in part on exports. He denounced the $6 trillion spent and the lives lost in the Middle East over the last 15 years, despite his administration’s decision to reauthorize troops in Afghanistan.

He toggled back and forth between telling farm-rich Iowa that he had fought for forgotten voters and lauding the wealth of Gary D. Cohn, his top economic adviser and a former executive at Goldman Sachs, the Wall Street giant that Mr. Trump derided in commercials in 2016.

“In those particular positions, I just don’t want a poor person — does that make sense?” he said of Mr. Cohn’s job and that of Commerce Secretary Wilbur Ross, another immensely wealthy man whom Mr. Trump lauded as a “legendary Wall Street genius.”

“Brilliant business minds” are what the economy needs, he said.

And the president frequently embellished details during his speech, or told outright falsehoods. He tried to catch himself at one point, saying, “I have to be a little careful, because they’ll say, ‘He lied!’”

But he nonetheless plowed ahead, including misstating whether the Paris climate agreement, from which he plans to withdraw the United States, is binding. While doing so, he also prompted the audience to name the agreement themselves. “P… p… p,” he said.

“Like hell it’s nonbinding!” thundered Mr. Trump, who in fact called the accord nonbinding in his Rose Garden speech announcing the withdrawal this month.

“We’re not even campaigning, and look at this crowd!” he said at another point. The rally was advertised, sponsored and organized by his campaign committee.

He also repeated his frequent, untrue campaign refrain that the United States is one of the world’s highest-taxed nations.

The president dismissed the potency of wind-harnessed energy in a state filled with thousands of turbines. “I don’t want to just hope the wind blows to light up your house and your factory,” he said, “as the birds fall to the ground.”

And he vented throughout against the news media: “the fake news,” he said, one of his favorite and most therapeutic invocations.

Mr. Trump also condemned Democrats as “obstructionists” — but then added that he wanted to work with them and might be damaging those prospects. “But who cares,” he concluded. He ignored the fact that Republicans hold majorities in Congress.

When he mentioned Hillary Clinton, the crowd lustily chanted, “Lock her up,” as if the election had not taken place.

It was the first trip Mr. Trump had taken west of the Mississippi River since he became president. His opening acts included his pregnant daughter-in-law, Lara, who is married to his son Eric. She suggested that complaints against the president were generated by people who “are very scared of what he’s going to do.”

Jeff Kaufmann, the chairman of the Republican Party of Iowa, took an unusual shot at Senator Ben Sasse, Republican of Nebraska, a frequent Trump critic who has himself been perceived as a potential presidential candidate.

Throughout the arena, Mr. Trump’s fans were adamant about whom they blamed for his troubles.

“What I’m frustrated about, and I hear this, that people are saying he’s not doing anything — how can you do something if people are resisting?” said Wendy Lemke, 65, of Cedar Falls.

After Mr. Trump had talked for over 60 minutes, diverting from his teleprompter repeatedly, he decided to wrap it up. Someone in the crowd yelled that they did not want him to go.

“I don’t want to leave, either!” Mr. Trump called back.