US President Barack Obama signs strategic Afghan accord
Mr Obama is also due to give a TV address to Americans back home.
The visit coincides with the first anniversary of Osama Bin Laden's killing in Pakistan.
It was a year ago that US special forces carried out a raid on Bin Laden's compound in Abbottabad and killed the leader of the al-Qaeda network.
After Mr Obama's arrival, Mr Karzai said a post-war agreement would seal an "equal partnership" between Afghanistan and the United States, reports say.
Analysis
Air Force One, the jumbo jet carrying President Obama, landed well after dark at the Bagram Air Base, north of Kabul. The president then flew on to the Afghan capital by helicopter.He will only be on the ground for a few hours. But the strategic partnership he and President Karzai have just signed is the product of months of difficult negotiations.
Only when differences over night raids by special forces and the handling of prisoners were ironed out did the agreement finally fall into place.
Later, Mr Obama thanked US troops in Afghanistan, saying Osama Bin Laden got justice a year ago.
He warned US troops of further hardship ahead in Afghanistan, but told them "there is a light on the horizon" after more than a decade of war.
The president called the agreement he signed with Mr Karzai "a responsible transition to Afghans taking control of their own country".
He said the change would not happen overnight because the US would not risk the gains so many had sacrificed to achieve.
"The reason America is safe is because of you," he added.
Symbolic step
Mr Obama will not make specific decisions on further reductions of US forces in Afghanistan until the autumn of 2012, the officials added.
Mr Obama is due to make his TV address from Bagram air base at 23:30 GMT.
The agreement is a first, symbolic step towards setting out a long-term relationship, says the BBC's Paul Adams in Washington.
It is designed to reassure the people of Afghanistan that they are not about to be abandoned when Nato ends its operations there in 18 months.
It is also meant to send a signal to the Taliban that it cannot simply expect to take over again when the Americans leave, our correspondent adds.
This is President Obama's third trip to Afghanistan since taking office.