He also made a surprise and secret visit to Baghdad in April 2009, and while in Iraq he addressed U.S. troops at Camp Victory.
Despite complaints about corruption and suspicions about the voting that led to Karzai's re-election in the fall, Jones said Karzai is an "adequate strategic partner" who was democratically elected in a sovereign nation.
Relations between Obama and Karzai are "fine," Jones said before today's meeting, and the two leaders last spoke by video teleconference on March 15.
Karzai learned on Thursday of Obama's plans to visit Afghanistan, officials said.
"This is something that simply has to be done," Jones said after the meeting. "We have to have the strategic rapport with President Karzai and his cabinet to understand how we are going to succeed this year in reversing the momentum the Taliban and the opposition forces have been able to establish since 2006."
They may have had to talk to Karzai, but the Obama team sounded decidedly more enthusiastic about addressing the troops and U.S. State Department employees.
"One of the main reasons I'm here is to just say thank you for the incredible efforts of our U.S. troops and our coalition partners," Obama said after meeting Karzai. "They make tremendous sacrifices far away from home, and I want to make sure they know how proud their commander-in-chief is of them."
The Afghanistan visit could help Obama as he continues to press the war, ABC News military consultant Gen. Jack Keane suggested.
"It strengthens his resolve and commitment to see the issue through, that is the war, and it also enables him to establish and continue a relationship with the leaders of Afghanistan," Keane said.
"It surprises [the troops] that he's there," Keane added. "It reinforces everything that they're doing. They always have tremendous admiration and respect, you know, for their commander-in-chief, regardless of what political party."
At Bagram today, Obama told the troops that the feeling from U.S. government officials, regardless of political party, is mutual.
"Sometimes when you're watching TV, the politics back home might look a little bit messy, and people are yelling and hollering, and Democrats this and Republicans that," Obama said. "I want you to know this: There's no daylight when it comes to supporting all of you. There's no daylight when it comes to supporting our troops. That brings us together."
Initially, Obama struck a jovial note as he took the stage at the air base.
"How's it going, Bagram?" he asked, to applause. "It turns out that the American people, they let me use this plane called Air Force One, so I thought I'd come over and say hello."
But his tone changed as he laid out the stakes of the war in Afghanistan.
"Your services are absolutely necessary, absolutely essential to America's safety and security," Obama said.
"This is the region where the perpetrators of that crime [on 9/11], al Qaeda, still base their leadership," Obama said. "Plots against our homeland, plots against our allies, plots against the Afghan and Pakistani people are taking place as we speak right here.
"If this region slides backwards," he added, "if the Taliban retakes this country and al Qaeda can operate with impunity, then more American lives are at stake. ... As long as I'm your commander in chief, I am not going to let that happen. That's why you are here."