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.