RIYADH, Saudi Arabia — President Trump on Sunday pivoted away from his strident assessment of Islam as a religion of hatred as he sought to redefine American leadership in the Middle East and rally the Muslim world to join him in a renewed campaign against extremism.

Addressing dozens of leaders from across the Muslim world who had gathered in Saudi Arabia, Mr. Trump rejected the idea that the fight against terrorism was a struggle between religions, and he promised not to scold them about human rights in their countries. But he challenged Muslim leaders to step up their efforts to counter a “wicked ideology” and purge the “foot soldiers of evil” from their societies.

“This is not a battle between different faiths, different sects or different civilizations,” Mr. Trump said in a cavernous hall filled with heads of state eager to find favor with the new president. “This is a battle between barbaric criminals who seek to obliterate human life and decent people, all in the name of religion, people that want to protect life and want to protect their religion. This is a battle between good and evil.”

The president’s measured tone here was a far cry from his incendiary language on the campaign trail last year, when he said that “Islam hates us” and called for a “total and complete shutdown” of Muslims entering the United States.

Throughout his visit, a less volatile president emerged, disciplined and relentlessly on message in a way he is often not at home. He did not brag about his electoral victory and avoided tangents. With few exceptions, he stuck carefully to his teleprompter. His mood has been sober and careful.

By refusing to hold news conferences or answer questions during brief photo opportunities, Mr. Trump orchestrated a sense of diplomatic calm that contrasted sharply with the chaos that usually surrounds him in Washington. He has not used Twitter as a cudgel against adversaries since his overseas trip began.

In his speech on Sunday, he made no mention of the executive orders he signed after taking office barring visitors from several predominantly Muslim countries. Instead, he described Islam as “one of the world’s great faiths” and called for “tolerance and respect for each other.”

Image

Mr. Trump addressed leaders from across the Muslim world who gathered on Sunday in Riyadh, Saudi Arabia.CreditStephen Crowley/The New York Times

While in the past Mr. Trump repeatedly criticized President Barack Obama and others for not using the phrase “radical Islamic terrorism,” his staff sought to ensure that he would not use it before this Muslim audience. The final draft of the speech had him instead embracing a subtle but significant switch, using the term “Islamist extremism.” Islamist is often defined to mean someone who advocates Islamic fundamentalism, and some experts prefer its use to avoid tarring the entire religion.

When that moment in the speech came, however, Mr. Trump went off script and used both words, Islamic and Islamist. “That means honestly confronting the crisis of Islamic extremism and the Islamists and Islamic terror of all kinds,” he said. An aide said afterward that the president was “just an exhausted guy” and had tripped over the term, rather than rejected the language suggested by his aides.

But if the speech during the second day of a nine-day overseas trip was intended as a sort of reset from his campaign and early presidency, it was also meant to turn away from Mr. Obama’s approach. Rather than preach about human rights or democracy, Mr. Trump said he wanted “partners, not perfection.” And he said it was up to Muslim leaders to expunge extremists from their midst.

“Drive them out,” he said. “Drive them out of your places of worship. Drive them out of your communities. Drive them out of your holy land. And drive them out of this earth.”

Mr. Trump received a warm welcome in the room as Muslim leaders put behind them the messages of the campaign and the attempted travel ban, and he has gotten along well with fellow leaders, who have turned to flattery.

“You are a unique personality that is capable of doing the impossible,” President Abdel Fattah el-Sisi of Egypt told him.

But some activists back in the United States gave the president mixed reviews at the start of his trip.

“While President Trump’s address today in Saudi Arabia appears to be an attempt to set a new and more productive tone in relations with the Muslim world, one speech cannot outweigh years of anti-Muslim rhetoric and policy proposals,” Nihad Awad, the executive director of the Council on American-Islamic Relations, said in a statement.

The speech was meant as a centerpiece of Mr. Trump’s two-day stay here before he heads to Jerusalem early Monday, and it was part of a larger drive to plant the United States firmly in the camp of Sunni Arab nations and Israel in their confrontation with Shiite-led Iran. To firm up such a coalition, he spent hours meeting individually with leaders from Egypt, Bahrain, Qatar and Kuwait, then with more Muslim leaders in larger groups.

“This administration is committed to a 180-degree reversal of the Obama policy on Iran,” said Mark Dubowitz, the chief executive of the Foundation for Defense of Democracies, a nonprofit research organization in Washington. “They see the Iranian threat as fundamentally linked to the nature and behavior of the regime and its revolutionary and expansionist ideology.”

Mr. Trump toured the new Global Center for Combating Extremist Ideology in Riyadh, which employs 350 technicians tracking online radicalism and monitoring 100 television channels in 11 languages. The Trump administration and Saudi Arabia also announced the creation of a joint Terrorist Financing Targeting Center to formalize longstanding cooperation and search for new ways to cut off sources of money for extremists.

Mr. Trump made little mention of human rights in any of the meetings, and he promised in his speech not to do so publicly. “We are not here to lecture,” he said. “We are not here to tell other people how to live, what to do, who to be, or how to worship. Instead, we are here to offer partnership — based on shared interests and values — to pursue a better future for us all.”

That approach drew bipartisan criticism back in Washington. “It’s in our national security interest to advocate for democracy and freedom and human rights,” Senator Marco Rubio, Republican of Florida, said on CNN’s “State of the Union.” On the same program, Representative Adam B. Schiff, Democrat of California, called it “a terrible abdication of our global leadership.”

Image

Mr. Trump addressed leaders from across the Muslim world who gathered on Sunday in Riyadh, Saudi Arabia.CreditStephen Crowley/The New York Times

Michele Dunne, the director of the Middle East program at the Carnegie Endowment for International Peace, said the president had laid blame for terrorism on Muslim leaders who he says have not done enough. “There are elements of truth to Trump’s narrative,” she said, “but it ignores the deeper grievances, the political and economic injustices, that make young people in the region especially susceptible to extremist ideologies at this particular time.”

And yet the change in the president’s tone about the relationship between Islam and terrorism was striking. As he assailed Mr. Obama last year for not using the phrase “radical Islamic terrorism,” Mr. Trump asserted that “anyone who cannot name our enemy is not fit to lead this country.” He used the phrase again in his inaugural address in January.

Still, General McMaster said in an interview broadcast on ABC’s “This Week” on Sunday that Mr. Trump had been listening to the Muslim leaders he has met since becoming president and understood their views better. “This is learning,” General McMaster said.

Secretary of State Rex W. Tillerson told reporters, “The president clearly was extending a hand, and understanding that only together can we address this threat of terrorism.”

While Mr. Trump’s administration is still appealing court rulings that blocked his temporary travel ban, the president has not publicly raised the issue as much lately, and the page on his campaign site calling for the “total and complete shutdown” of Muslim immigration has been taken down.

Some advisers who advocated stronger action and language about what they call the Islamic threat have either left the administration or faded in influence. Michael T. Flynn, General McMaster’s predecessor as national security adviser, was fired for other reasons. Stephen K. Bannon, the president’s chief strategist, has lost sway. And Sebastian Gorka, a deputy assistant to the president, has been reported to possibly be leaving the White House at some point.

Even so, the hard-liners found enough to be happy with in the speech. After the president was finished on Sunday, Mr. Gorka wrote on Twitter: “After 8yrs disastrous terror-enabling policies we now have @POTUS: ‘We r going 2 defeat terrorism & send its wicked ideology in2 OBLIVION.’”

Correction:May 23, 2017

A picture caption on Monday with the continuation of an article about a speech by President Trump in Riyadh, Saudi Arabia, misidentified the Emir of Kuwait. He is Sheikh Sabah Al-Ahmad Al-Jaber Al-Sabah — not Sheikh Jaber al-Ahmed al-Sabah, an earlier emir, who died in 2006.

A version of this article appears in print on , on Page A1 of the New York edition with the headline: Shifting Tone, President Saves Dark Words for a Faith’s Fringe. Order Reprints | Today’s Paper | Subscribe