(CNN) -- President Obama told West Point graduates that the United States faces "difficult days ahead" in its fight against insurgents in Afghanistan and said that the threat posed by al Qaeda operatives across the globe "will not go away soon."
Speaking at the U.S. Military Academy commencement in New York, Obama praised the graduates for their achievements and laid out a scenario of military and societal challenges in what is the ninth West Point commencement during the wars in Iraq and Afghanistan and the fight against international terrorism.
"This time of war began in Afghanistan, a place that may seem as far from this peaceful bend in the Hudson River as anywhere on Earth," Obama said, referring to a conflict that started after the al Qaeda terror network attacked the United States on September 11, 2001.
"The war began only because our own cities and civilians were attacked by violent extremists who plotted from that distant place, and it continues only because that plotting persists to this day."
While the United States and its allies battled in Afghanistan, the U.S. military launched an invasion of Iraq in 2003, toppling the Saddam Hussein regime and battling insurgents for years until that war began to wind down in the last couple of years. But the Afghan conflict persists as the United States and its allies battle tenacious militants from the Taliban militant movement.
Obama said as the Iraq war ends, America is "pressing forward in Afghanistan" and faces a "tough fight" against a nimble insurgency.
"From Marja to Kandahar, that is what the Taliban has done through assassination, indiscriminate killing and intimidation," Obama said, referring to the main militant and two southern Afghan battlegrounds. "And any country that has known decades of war will be tested in finding political solutions to its problems, and providing governance that can sustain progress and serve the needs of its people. "
Obama said that even though the nature of the war has changed in the past nine years, it remains just as important as it was after the 9/11 attacks on the World Trade Center and Pentagon. He said the United States has helped bring hope and sovereign government to Afghanistan, but "there will be difficult days ahead."
"We toppled the Taliban regime; now we must break the momentum of a Taliban insurgency and train Afghan security forces," he said. "We will adapt, we will persist, and I have no doubt that together with our Afghan and international partners, we will succeed in Afghanistan."
As for al Qaeda's activities, Obama defended the "campaign to disrupt, dismantle and to defeat al Qaeda," saying it's an "international effort that is necessary and just."
While he said there has been "more success in eliminating al Qaeda leaders in recent months than in recent years," the group will continue its recruitment efforts.
"We see that in bombs that go off in Kabul and Karachi. We see it in attempts to blow up an airliner over Detroit or an SUV in Times Square, even as these failed attacks show that pressure on networks like al Qaeda is forcing them to rely on terrorists with less time and space to train," he said. "We see it in al Qaeda's gross distortion of Islam, their disrespect for human life, and their attempts to prey upon fear and hatred and prejudice."
Obama dismissed al Qaeda and its affiliates as "small men on the wrong side of history," but acknowledged that the threat they pose "will not go away soon."
"This is a different kind of war," he said. "There will be no simple moment of surrender to mark the journey's end. No armistice or banner headline."
The president said America's "strength and resilience" will counter people attempting to sow fear.
"Terrorists want to scare us," he said, but "New Yorkers go about their lives unafraid. Extremists want a war between America and Islam, but Muslims are a part of our national life, including those who serve in our Army. Adversaries want to divide us, but we are united by our support for you -- soldiers who send a clear message that this country is both the land of the free and the home of the brave."
Obama made reference to West Point's diversity, pointing out that women in uniform are playing "indispensable role in our national defense."
They include West Point's No. 1 overall cadet and valedictorian, Liz Betterbed and Alex Rosenberg. Obama noted it was the first time the academy's two top awards were earned by female cadets.
"America's Army represents the full breadth of the American experience," with cadets hailing from all walks of life, Obama said. The president noted that one thing that sets the cadets apart is that they "have come together to prepare for the most difficult tests of our time" and know they are being sent into "harm's way."
"And through a period when too many of our institutions have acted irresponsibly, the American military has set a standard of service and sacrifice that is as great as any in this nation's history," he said.
Obama also stressed that economic and technological innovation "must be a foundation of American power" and that the efforts of America's armed forces must be complemented by effective diplomacy, world development and security.
"We need intelligence agencies that work seamlessly with their counterparts to unravel plots that run from the mountains of Pakistan to the streets of our cities; law enforcement that can strengthen judicial systems abroad and protect us at home; and first responders who can act swiftly in the event of earthquakes, storms and disease. "
Obama said the world's burdens cannot just be America's, and alliances that has served the United States well must be maintained, strengthened and widened.
"The international order we seek is one that can resolve the challenges of our times -- countering violent extremism and insurgency; stopping the spread of nuclear weapons and securing nuclear materials; combating a changing climate and sustaining global growth; helping countries feed themselves and care for their sick; preventing conflict and healing its wounds."