TAMPA, Fla. (AP) -- Closing out two terms as a president at war, Barack Obama staunchly defended his counterterrorism strategy as one that rejected torture, held to American values and avoided large-scale troop deployments, in an implicit effort to shape the strategy his successor might employ.

Obama came to MacDill Air Force Base, home to U.S. Special Operations Command and Central Command, to give his final speech on national security. He delivered a strident argument for his reliance on drone strikes and U.S. commandos rather than ground wars like those launched in Iraq and Afghanistan by his predecessor. Obama emphasized the need for the U.S. to uphold its values by respecting the rights of Muslims and trying terror suspects in civilian courts.

"We can get these terrorists and stay true to who we are," Obama said.

"Rather than offer false promises that we can eliminate terrorism by dropping more bombs, or deploying more and more troops, or by fencing ourselves off from the rest of the world, we have to take a long view of the terrorist threat," Obama told troops gathered in an airplane hangar. "We have to pursue a smart strategy that can be sustained."

In describing the nature of the threat after eight years of his leadership, Obama sought to strike a careful balance, arguing at once that "violent extremism will be with us for years to come" and that terrorists "don't pose an existential threat" to the U.S. He said unlike previous wars against other nations, it was unlikely this conflict would end with a "clearly defined victory."

Though White House officials said the speech was planned before Donald Trump was elected, Obama's remarks were clearly tailored to address some of Trump's proposals.

In a warning that appeared aimed at Trump, who has called for barring Muslim immigrants temporarily, Obama said the U.S. doesn't impose religious tests. He forcefully defended his decision to bar the use of torture against detainees while chastising Congress for refusing to let him shutter the Guantanamo Bay detention center, which Obama called a "blot on our national honor."

Amnesty International USA urged the incoming commander in chief to heed Obama's advice, arguing that the speech "offers lessons for Trump."

Obama acknowledged he wasn't entirely successful in what he has described as his push to take the U.S. off its wartime footing. He has been forced to rely on more than 15-year-old law, passed by Congress after 9/11, as the legal underpinning for his campaign against the Islamic State group, but pointed the finger at Congress for failing to update it.

"Democracies should not operate in a state of permanently authorized war," Obama said.

Trump has said little about how he intends to combat extremist groups, arguing that ambiguity and unpredictability are assets that deny the enemy a chance to plan ahead. Still, all signs suggest he'll pursue a more muscular, military-driven approach, including his selection of hawkish aides for his team such as retired Gen. Michael T. Flynn for national security adviser.

The president-elect has argued that Obama's decision to withdraw the bulk of troops from Iraq created a power vacuum that allowed IS to form and seize territory. Obama said that was because Baghdad refused to sign a pact granting legal protections to U.S. troops to stay, though officials have acknowledged privately over the years that Obama never forcefully pushed for such a deal.

Obama came into office telling a war-weary nation he would wind down two wars and prevent new ones. Obama said his use of drones, for example, had saved civilian lives, arguing that airstrikes would have been less precise and ground troops more deadly.

"You have to weigh the alternatives," Obama said.

But Obama's approach most notably came up short in Syria, where Obama long ago predicted that Syrian President Bashar Assad would lose his grip on power. But Assad's control appears stronger than it has in years while the brutal civil war rages on.

While U.S. troop casualties declined significantly under Obama's approach, the U.S. is now fighting in far more corners of the globe, which Obama attributed to a metastasizing extremist threat.

The U.S. is currently launching strikes in Syria, Somalia, Libya and Yemen, according to a report to Congress the White House released this week. Additional U.S. troops and assets are also in Jordan, Djibouti, Turkey, Egypt and Cameroon to support counterterrorism missions, while other overseas operations remain classified.

Much of the counterterrorism mission is being carried out not by traditional ground troops who have traditionally done most of the fighting in U.S. wars, but by commandos like the Army Delta Force and Navy SEALs. Their agility, advanced training and light footprint make them attractive for fighting in places where the U.S. doesn't want to get bogged down.

Before taking the stage for his speech, Obama met with top military leaders at the base, including Gen. Raymond Thomas, who heads U.S. Special Operations Command. He also told troops serving at the base that it had been the privilege of his lifetime to serve as their commander in chief.