German special forces were involved in the non-violent handover at a mosque on the outskirts of Kabul after the man's 32-month ordeal, media reports said.
"The government is very relieved that a German national who was kidnapped more than two years ago in Pakistan has been freed in Afghanistan," a German
foreign ministry spokeswoman told AFP.
He was now in the care of the German government, had received a medical check-up and counselling and was "doing well under the circumstances", said the spokeswoman, adding that an international "partner" had helped win his freedom.
The Bild newspaper, which first reported the release, previously identified the hostage as Bernd Mühlenbeck and said he worked for the German aid group Welthungerhilfe (World Hunger Aid).
The group was helping victims from Pakistan's devastating 2010 floods that affected up to 21 million people.
Bild said Germany's KSK special forces were involved in the handover, but that its officers had been handed the hostage without an armed confrontation.
The kidnappers had forced their captive to march through regions of eastern Afghanistan, the report said.
News portal Spiegel Online said the kidnappers were believed to be linked to the Taliban and had repeatedly threatened to kill the hostage in video messages, although it pointed out that such threats are common from criminal groups.
The German foreign ministry had set up a crisis unit, but the government and aid group had requested the media not to cover the case to avoid further danger to the hostage.
Criminals frequently snatch foreigners and locals for ransom in parts of Pakistan, sometimes selling their hostages on to Taliban- and Al-Qaeda-linked groups.
The German aid worker was kidnapped with his Italian colleague in Pakistan's central shrine city of Multanabout 400 kilometres (250 miles) southwest of the capital Islamabad on January 19th, 2012, local police said at the time.
"Three gunmen barged into a house and abducted an Italian and a German national at gunpoint," Multan city police officer Aamir Zulfiqar Khan told AFP at the time.
A local security official told AFP the kidnappers pistol-whipped a private security guard, then snatched the aid workers, but left behind a Western woman in the house that the group rented.