Merkel - whose country expects one million asylum seekers this year, about half from war-torn Syria - made clear that most people from Afghanistan would not be granted refuge in the EU's biggest economy.
While some people facing acute danger because they had worked with German military forces in Afghanistan would get asylum, those who came simply in search of "a better life" would have to go back, she said.
Where people are motivated by economic factors rather than a direct threat to life and limb, "in these cases we will have to send people back to Afghanistan," Merkel said at a joint press conference.
She and Ghani agreed that the key was to develop the country of 35 million people, where the Kabul-based government has for years been at war with Islamist fundamentalist Taliban insurgents.
"We have to do everything in our power to develop Afghanistan and create a better future for its people," Merkel said.
The almost 1,000-strong German deployment under NATO command would keep training Afghan security forces, with a focus on battling human traffickers and networks that counterfeit passports, she said.
Ghani described the people-smuggling as an "appalling and very expensive process", where people pay $20,000 to $25,000 (€19,000-€23,600) for a very risky journey.
Merkel said a crucial alternative to becoming a refugee would be to stay in "safe zones" for displaced peoples within Afghanistan, where development efforts could be concentrated.
"While there are areas with low security, there are also regions in Afghanistan that offer high and adequate security," she said.
People there should be able to have "prospects for the future" and development aid there should focus on providing shelters and jobs training.
Ghani said Afghanistan was faced with problems from "terrorism, illegal activities focused on drugs and narcotics, to illegal migration".
It was fundamental "to deal with the root causes ... instability and poverty," he added, thanking Germany for its "enormous commitment to the well-being of all Afghan people."