(CNN) - President Barack Obama is expected to return to the United States on Monday morning after a surprise visit to Afghanistan, where he met with his Afghan counterpart and reiterated the need to wipe out terror networks.
Obama slipped into Bagram Air Base near Kabul under the cover of darkness on Sunday.
He met with about 2,000 troops at the U.S. base and told them their work is significant to security at home.
"I know it's not easy," he said. "If I thought for a minute that America's vital interests were not served, were not at stake here in Afghanistan, I would order all of you home right away."
The United States has made progress in the fight against al Qaeda and its allies, Obama said.
"All of that makes America safer, and we are going to keep them on the run," he said. "Because that is what is going to be required in order to ensure that our families back home have the security that they need."
Earlier, Obama met with President Hamid Karzai to discuss progress by the Afghan government in strengthening its ability to run the country and provide security for its people. After the 30-minute meeting, Obama said he wanted to send a "strong message" that the partnership between the nations would continue.
Karzai thanked the United States, pointing out that American taxpayers have helped rebuild his country.
During his trip, the president made clear that the visit was to encourage the roughly 80,000 U.S. troops in the country.
"The United States of America does not quit once it starts on something. ... We keep at it," he told the troops. "We persevere. And together, with our partners, we will prevail. I am absolutely confident of that."
Before his departure, Obama also met with U.S. Ambassador Karl Eikenberry and Gen. Stanley McChrystal, the commander of allied troops in Afghanistan.
The trip began in secrecy, with the president leaving his Camp David retreat. He flew to Afghanistan on Air Force One, landing at Bagram Air Base at 7:24 p.m.
Obama then flew on a helicopter to the Presidential Palace to meet with Karzai.
The U.S. president is expected to land at Andrews Air Force Base in Maryland at 9 a.m. ET.