German President Christian Wulff arrived on Sunday in Afghanistan on a state visit, where he was met with full military honours by his Afghan counterpart, Hamid Kharzai, DPA reported.
Karzai told Wulff - whose role is largely ceremonial - Germany was an "old friend of Afghanistan."
Wulff said that Germany would remain a friend and partner for Afghanistan even after the withdrawal of international troops planned for 2014.
"Germany will not abandon Afghanistan," Wulff said on what was the first state visit by a German president for 44 years.
The trip was not announced in advance for security reasons.
The president, after his meeting with Karzai, met representatives of Afghan civil society involved in human rights especially the rights of women.
The meeting of the two presidents will help prepare for a conference on Afghanistan scheduled to be held in Bonn in early December.
Wulff's predecessor Horst Koehler visited German troops in Afghanistan in May 2010 but did not meet Karzai.
Koehler resigned shortly afterwards due to controversial comments he made about German military involvement in Afghanistan.
The visit is Wulff's first to the country. He said he wanted to assess the state of the handover from NATO troops to Afghan forces.
German Chancellor Angela Merkel travelled to Afghanistan in December.
Around 5,000 German troops are based in Afghanistan. They are due to begin withdrawing at the end of this year.
Germany's deployment in Afghanistan is highly controversial among parts of the German public, with a recent spate of firebomb attacks by leftists on the Berlin rail network being partly claimed as a response to the military intervention.