Obama noted the progress that has been made in Afghanistan in recent years but cautioned there are still difficult challenges that must be overcome.
"There are going to be ups and downs," Obama said. "There is going to be some hard fighting in the next several months."
The US president also said the two countries had a "shared goal to disrupt, dismantle, and defeat al-Qaeda".
"We will sustain a robust commitment to Afghanistan going forward."
In turn, Karzai admitted that Afghanistan still had its "shortcomings", but he promised to work to build a better government with help from the US.
In the course of his visit, the Afghan leader is also expected to meet Senate and House leaders.
Talks with Obama, the centrepiece of his trip, followed meetings with other senior US officials to patch over differences at a pivotal time in the nearly nine-year-old war in Afghanistan.
Washington criticised Karzai openly in recent months for tolerating government corruption and the Afghan leader lashed back with a series of anti-Western criticisms.
Karzai met Hillary Clinton, the US secretary of state, on Tuesday who conceded that US relations with Afghanistan had been strained but assured Karzai that the US would remain committed to Afghanistan long after troops left.
|Clinton said the US would remain committed to Afghanistan long after troops left [AFP]
During an evening reception at the state department, with Karzai at her side, Clinton said that the enormous sums of military and humanitarian assistance offered to Afghanistan by a wide range of nations and international organisations are a "great vote of confidence in you" - and in his government.
"As we look toward a responsible, orderly transition in the international combat mission in Afghanistan, we will not abandon the Afghan people," Clinton told Karzai.
Her pledge of a long-term US commitment to Afghanistan addresses one of the Afghan government's major concerns.
Karzai's trip comes at a pivotal time in his country.
Nato is preparing for an assault against the Taliban in the southern province of Kandahar, and Afghan officials are preparing for a meeting of tribal leaders who will discuss how to promote peace.
Both countries regard the Taliban as a threat, but they have different views of how to deal with them.
Al Jazeera's Patty Culhane, reporting from Washington, said the Taliban issue "was one of the main sticking points".
"For the last nine years, politicians have made very little distinction between al-Qaeda, which launched the September 11 attacks, and the Taliban. So, for President Obama to sit down and negotiate with the leadership of the Taliban could cause a huge outrage among the American public," Culhane said.
"It is important to point out, however, that the department of defence has been spending money to help with reintegration - but that's for lower level Taliban fighters - so it seems that is was a sticking point that they possibly worked through today."
The Obama administration intends to begin withdrawing troops from Afghanistan in July 2011, but is wary of any peace deal that includes unrepentant Taliban leaders.
Karzai, meanwhile, sees reconciliation with Taliban fighters as his country's best hope for a lasting peace and worries that the US and its Nato allies will leave Afghanistan to fend for itself once any deal is struck.
"The ability to disagree on issues of importance to our respective countries and peoples is not an obstacle to achieving our shared objectives"
US secretary of state
Clinton and Karzai on Tuesday both acknowledged that differences have complicated efforts to stabilise Afghanistan more than eight years after the Taliban was ousted from power by a US-led invasion.
"The ability to disagree on issues of importance to our respective countries and peoples is not an obstacle to achieving our shared objectives," Clinton said.
"Rather, it reflects a level of trust that is essential to any meaningful dialogue and enduring strategic partnership."
Karzai agreed it was natural for Kabul and Washington to see the situation differently while working together toward the same goals.
"As two mature nations and two mature governments - by now the Afghan government is mature, too - we will be having disagreements from time to time," Karzai said.
Relations reached a low point last year after Karzai won an election widely condemned for fraud.
In March, the Obama administration publicly accused Karzai of tolerating corruption and drug trafficking.
The Afghan leader, in turn, accused the Westof undermining him.
Karzai's international reputation took a battering when a UN-backed fraud watchdog threw out one-third of the votes cast for him in the presidential election.