President Obama mostly strayed away from politics in the final commencement address of his presidency, but defended his foreign policy legacy to U.S. Air Force Academy graduates -- saying that America cannot afford to be isolationist.

“America cannot shirk the mantle of leadership,” Obama said. “We can’t be isolationists. It’s not possible in this globalized interconnected world.”

Obama told the cadets the U.S. still maintains the strongest military force in the world, and argued that American leadership should be centered around continued nurturing of international alliances.

“In these uncertain times it’s tempting sometimes to pull back and try to wash our hands of conflicts that seem intractable, let other countries fend for themselves,” Obama said. “But history teaches us from Pearl Harbor to 9/11 that oceans alone cannot protect us.”

Reflecting on his seven years as Commander-In-Chief, Obama again said he made a mistake in not planning for "a day after" U.S. airstrikes in Libya, and defended his controversial decision not to use U.S. forces to remove Syrian President Bashar al-Assad.

"We should never rush into war," Obama said. "Sending troops into harm's way must always be a last resort."

The commencement address was the third for President Obama in 2016, and the 26th and final one of his presidency.