President Obama lauded the U.S. for being a leading force for peace and security in the world while assuring that pulling out of Afghanistan wouldn’t let the country become a haven for terrorists.

Obama told the American Legion convention that “the United States is better positioned to lead in the 21st century than any nation on Earth.”

“It’s not even close. We have the most powerful military in history. That’s certainly not close. From Europe to Asia, our alliances are unrivaled. Our economy is the most dynamic. We’ve got the best workers. We’ve got the best businesses. We have the best universities and the best scientists,” he said.

“…Nobody else can do what we do. No other nation does more to underwrite the security and prosperity on which the world depends. In times of crisis, no other nation can rally such broad coalitions to stand up for international norms and peace. In times of disaster, no other nation has the capabilities to deliver so much so quickly. No nation does more to help citizens claim their rights and build their democracies. No nation does more to help people in the far corners of the Earth escape poverty and hunger and disease and realize their dignity.”

The president continued by noting “even countries that criticize us, when the chips are down and they need help, they know who to call.”

“They call us. That’s what American leadership looks like. It’s why the United States is and will remain the one indispensable nation in the world,” he said. “Now, sustaining our leadership, keeping America strong and secure means we have to use our power wisely. History teaches us of the dangers of overreaching and spreading ourselves too thin and trying to go it alone without international support or rushing into military adventures without thinking through the consequences.”

“And nobody knows this better than our veterans and our families, our veteran families because you’re the ones who bear the wages of war. You’re the ones who carry the scars. You know that we should never send American sons and daughters into harm’s way unless it is absolutely necessary and we have a plan and we are resourcing it and prepared to see it through.”

He added the U.S. “has to lead with strength and confidence and wisdom.”

“And that’s why after incredible sacrifice by so many of our men and women in uniform, we removed more than 140,000 troops from Iraq and welcomed those troops home. It was the right thing to do,” Obama said.

He praised his administration’s drive against “al-Qaeda’s leadership in the tribal regions in Afghanistan and Pakistan,” and stressed that the war would be coming to a close for the U.S. in four months with the pullout from Afghanistan.

“And now, as Afghans continue to work towards the first democratic transfer of power in their history, Afghan leaders need to make the hard compromises that are necessary to give the Afghan people a future of security and progress. And as we go forward, we’ll continue to partner with Afghans so their country can never again be used to launch attacks against the United States.”

He waited for applause after this line; he got a smattering of claps after the pause.

Obama said he’s “always made clear” that “the blows we’ve struck against al-Qaeda’s leadership don’t mean the end to the terrorist threat.”

“Al-Qaeda affiliates still target our homeland. We’ve seen that in Yemen. Other extremists threaten our citizens abroad, as we’ve seen most recently in Iraq and Syria. As commander in chief, the security of the American people is my highest priority, and that’s why, with the brutal terrorist group ISIL advancing in Iraq, I have authorized targeted strikes to protect our diplomats and military advisers who are there,” he continued.

“And let me say it again, American combat troops will not be returning to fight in Iraq. We’ll not allow the United States to be dragged back into another ground war in Iraq. Because ultimately, it is up to the Iraqis to bridge their differences and secure themselves.”

The president referenced the parents of American journalist James Foley, stressing prayers were with them.

“But our message to anyone who harms our people is simple: America does not forget our reach is long. We are patient. Justice will be done. We have proved time and time again we will do what’s necessary to capture those who harm Americans to go after those who harm Americans. And we’ll continue to take direct action where needed to protect our people and to defend our homeland. And rooting out a cancer like ISIL won’t be easy, and it won’t be quick,” Obama said.

“But tyrants and murderers before them should recognize that kind of hateful vision ultimately is no match for the strength and hopes of people who stand together for the security and dignity and freedom that is the birthright of every human being.”