Mr. Obama said that the Islamic State had lost more than half its populated territory in Iraq and Syria. “As we take away more of their territory,” he said, “it exposes ISIL as the failed cause that it is. And it helps to undermine their ideology, which over time will make it harder for them to recruit and inspire people to violence.”

Mr. Obama, his aides have said, would like to leave office with military offensives well underway to retake Mosul and Raqqa, the Syrian city that serves as the Islamic State’s de facto capital.

Still, Mr. Obama conceded that the battle for Mosul would be tough. In addition to expelling the militants, he said, Iraq and the United States would have to provide humanitarian aid to thousands of people who are likely to be displaced by the fighting. And he said they would have to “rebuild the city in a way that assures not only ISIL does not come back but extremist ideologies born out of desperation do not return.”

“This is going to be hard, this is going to be challenging,” he said. “We are going to be asking Congress to step up in support of this effort.”

On his final visit to the United Nations General Assembly as president, Mr. Obama had hoped to summarize his diplomatic accomplishments and to lay out a blueprint of how to handle future crises overseas. But the attacks have created a sense of crisis at home, one magnified by the harsh words on the presidential campaign trail from Hillary Clinton and Donald J. Trump.

Mr. Obama’s hectic schedule captured the diplomatic, political and security crosscurrents. After speaking to reporters about the attacks, the president left to raise money for Democratic senatorial candidates.

Then, Mr. Obama returned to his hotel to meet with China’s prime minister, Li Keqiang. The White House said that Mr. Obama and Mr. Li pledged to coordinate efforts in the United Nations Security Council and through law enforcement channels to punish North Korea for its nuclear test on Sept. 9. Mr. Obama has often struggled to persuade the Chinese to crack down on the North Koreans.